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])) ) )
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.
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]))
)
)