Forum Discussion
Complex Filtering with Dates
- Anonymous8 years ago
You need a date table. Use the date field in this table as a filter in your report and then use this measure:
Measure = VAR selectedDate = SELECTEDVALUE(Date[Date]) RETURN CALCULATE( COUNTROWS(EmployementRecord), FILTER(EmployementRecord, EmployementRecord[StartDate] <= selectedDate && (EmployementRecord[EndDate] >= selectedDate || ISBLANK(EmployementRecord[EndDate])) ) )
Hi danielgatley
There are a few things you can do.
You can add the 'date' field onto the report page, set it as a filter and use that as your 'day selection'.
You could create a flag column based on the same SQL code and set that to either 1 or 0 and use that as your filter/current day value.
Do you have examples of where you are with it all?
Thanks
Shebr
So I went back and looked at the data and decided to add a coulmn which takes EndDate and if null replaces it with the current date. Doing this I can apply page level filters to specify dates and this gives me the results i'm after, so the question is how do I give the power to the user. Given my filtering needs a single date value compare against two seperate columns (<= StartDate and >= EndDate) what is my best options for achieving this? I did test using two slicers based on the StartDate and EndDate fields and this works when they are both set to the same date but this isn't exactly easy to use.
- Anonymous8 years agoNot applicable
You need a date table. Use the date field in this table as a filter in your report and then use this measure:
Measure = VAR selectedDate = SELECTEDVALUE(Date[Date]) RETURN CALCULATE( COUNTROWS(EmployementRecord), FILTER(EmployementRecord, EmployementRecord[StartDate] <= selectedDate && (EmployementRecord[EndDate] >= selectedDate || ISBLANK(EmployementRecord[EndDate])) ) )- danielgatley8 years agoFrequent Visitor
Thank you for the response SPG, just what I needed.
- shebr8 years agoResolver III
Hey danielgatley
If you need a quick fire way to create a full date table this is a great video.
Thanks
Shebr
- Anonymous6 years agoNot applicable
Hi, this solution you gave works for me only when I set a one day range in my date slicer.
How does the SELECTEDVALUE(date[Date]) knows which value is the higher and the lower set by the slicer?
Because in the formula are used whitout difference with the "selectedDate" variable.
FILTER(clusterhistory, clusterhistory[initdate] <= selectedDate&& (clusterhistory[finishdate] >= selectedDate || ISBLANK(clusterhistory[finishdate])))Thanks!!- Anonymous6 years agoNot applicable
I kept trying and I found the answer of my question. If you are around here and need it. Here it is:
Measure =VAR iniDate = MIN(Date[Date])
VAR endDate = MAX(Date[Date])RETURN CALCULATE( COUNTROWS(EmployementRecord),FILTER(EmployementRecord,EmployementRecord[StartDate] <= iniDate&& (EmployementRecord[EndDate] >= endDate || ISBLANK(EmployementRecord[EndDate]))))
- BI_HCV6 years agoFrequent Visitor
I know there is a long time ago, but I'm wondering if you have the pbix file to share?
I tried to set my data as you wrote but doesn't works.