Dynamic Measure From Date Slicer Not working as expected - date

I have similar problem statement of (PowerBI/DAX: Unable to correctly compare two dates)
where I'm selected the start date and end date from slicer and wrote DAX for the measures as
Start_Date = CALCULATE(Min('Calendar'[Date]),ALLSELECTED('Calendar'))
End_Date = CALCULATE(Max('Calendar'[Date]),ALLSELECTED('Calendar'))
And I use them to compare with a column and return TRUE or FALSE.
IsTrue_Flag = IF(table[prod_date]>=[Start_Date] && table[prod_date] <= [End_Date], TRUE, FALSE)
But all my values are turning as TRUE which is not the case.
Where did I go wrong with the DAX? please help

Related

DAX Calculate Billing Days Between Two Variable Dates

I have a dimdate table that is represented below. I have each day flagged as BusinessDay Y/N. I also have a DimSalesRep table that has a daily goal for each rep. I want to be able to allow users to input a StartDt and EndDt with filters on the report and have a calculated column look at the business days between those dates. I can calculate daysbetween with defined dates but I am unsure how I would use DAX with variable dates that are applied through Report filters.
I should also note I am not sure how best to handle a startdt and enddt filter based of the column, TheDate
Cheers!
Reference your dimdate table twice
StartDate = 'dimdate'
EndDate = 'dimdate'
and use this measure:
Num BusinessDays =
CALCULATE(
COUNTROWS('dimdate'),
'dimdate'[BusinessDay] = "Y",
'dimdate'[Date] >= SELECTEDVALUE(StartDate[Date]),
'dimdate'[Date] <= SELECTEDVALUE(EndDate[Date])
)

Joining a QUERY function with OR

I currently have a QUERY function which is set up based on a start date cell and an end date cell, formula as below:
=QUERY(Haulage!$A$3:$L$29," Select * Where A >= date """&text('2022 Stats'!S1, "yyyy-mm-dd")&""" AND A <= date """&text('2022 Stats'!T1, "yyyy-mm-dd")&"""")
This is working fine but I would like to adapt it so I can also narrow the query down further with the use of a dropdown. I have the following IF formula for this:
=IF('2022 Stats'!V1="All TOCs",""," AND LOWER(K) = LOWER('"&'2022 Stats'!V1&"') " )
This seems to yield the correct results but I am struggling to get the two to work together......
Link to sheet: https://docs.google.com/spreadsheets/d/1wTWuvFwMTqJ-sjIZbXWpGOS1WKwpODj2R8KAzqlqkuw/edit?usp=sharing
Try:
=QUERY(Haulage!A3:L29,
"where A >= date '"&TEXT('2022 Stats'!S1, "yyyy-mm-dd")&"'
and A <= date '"&TEXT('2022 Stats'!T1, "yyyy-mm-dd")&"'"&
IF('2022 Stats'!V1="All TOCs",,"
and lower(K) = '"&LOWER('2022 Stats'!V1)&"'"))

Date query with the current date between two date_time columns

I have a fusion table with two date_time columns. The fist one is the start date (Startdatum) and in the other column is the end date (Einddatum).
I want to do a query with the current date, and only show the KML-lines on a map where the current date lies between the start and end date.
I tried to use the code below to create a string with a date format:
var time_date = new Date();
var day = time_date.getDate();
var month = time_date.getMonth()+1;
var year = time_date.getFullYear();
var date = (year+"."+month+"."+day);
To show the KML-lines on the map I tried to use the following code:
layer = new google.maps.FusionTablesLayer({
map: map,
heatmap: { enabled: false },
query: {
select: "col2",
from: "1mOMP1seJq4FdiNTugsfylZaJc8sKcSlfJKUuTJjv",
where: "'Startdatum' <= date AND 'Einddatum' >= date"
},
options: {
styleId: 2,
templateId: 2
}
});
Unfortunatly the map shows all the KMS-lines regardless what date is in one of the columns.
What am I doing wrong?
the where-clause is wrong, it has to be
where: "Startdatum <= '"+date+"' AND Einddatum >= '"+date+"'"
the date-format seems to be wrong. Although the used format yyyy.MM.dd is defined in the documentation, it doesn't work. The format yyyy-MM-dd currently works for me(but it's not defined in the documentation).
var date = (year+"-"+month+"-"+day);
(in case that day and month be less than 10 they wouldn't match the pattern, but that doesn't seem to be an issue)
Beyond that: when you fix these 2 mentioned parts it currently works(for me), but I've tried it a couple of hours ago and got unstable results.

Has value function crystal reports

In my report I have 3 parameters when, week and year.
If I select When=schedule then the report should run for current week without considering year and week values given in parameter window.
If I select when=Now then the report should run for week value and month value that we have given in parameter window.
Please suggest.
I tried like this but not working.
if hasvalue({?Week}) and HasValue({?Year}) and {?When} = 'Now'
Then
{?Week} = {Command.WEEK} and {?Year} = {Command.YEAR}
else
({?Week} = DatePart ("ww", Currentdatetime) and {?Year} = DatePart ("yyyy", Currentdatetime)
In crystal report ISNULL and INSTR function will use in this condition.
ISNULL:- check the value is null, then return true else false.
INSTR :- check the substring in string, if found then give index else 0 return.
Check detail in links
http://publib.boulder.ibm.com/infocenter/rsahelp/v7r0m0/index.jsp?topic=/com.businessobjects.integration.eclipse.designer.doc/designer/Crystal_Syntax47.html
In your case
if isnull({?Week}) and isnull({?Year}) and isnull{?When}
Then
return false
else
//in else again check with if else condition
if {?When} = 'schedule'
then
do something
else
do something
My approach would be:
Instead of checking for null values for the parameters.. Give a default value for the parameter and check that value for the false condition.
Suppose let us take default value as None
if {?Week}="None" and {?Year}="None" and {?When} = 'Now'
Then
{?Week} = {Command.WEEK} and {?Year} = {Command.YEAR}
else
({?Week} = DatePart ("ww", Currentdatetime) and {?Year} = DatePart ("yyyy", Currentdatetime)
Note: Above code is just an example change it as per your requirement.
You can use by this way:
if {?Week}<>"" then {Command.WEEK}={?Week} else {Command.WEEK}={Command.WEEK}
Hope this will help.

database query with start and end date

I do a select and its working perfect but I want to change it to a select with a from and to date, how would I change my sample to do this? I will get the date from a richfaces calender,
I have a filter on my page that selects all the values for the sql select. so I want to a start and end date to that filter and only get the results between those dates. only "dd/MM/yyyy" can be used as its not necessary for the time
example of select:
myList = database.createQuery("SELECT t FROM Logging t WHERE t.No = :No and t.customer = :customer and t.project = :project and t.task = :tasks").setParameter("No", getNo()).setParameter("customer", getCustomer()).setParameter("project", getProject()).setParameter("task", getTask()).getResultList();
This resolved it for me: and t.date BETWEEN :startDate AND :endDate at the end and then just added the setParameter with the values I get from richfaces calender and works perfect!