Forum Discussion
Help with dynamic filtering
- 4 years ago
With a lot of help from jdbuchanan71 , I was finally able to solve the problem.
First, I created a Calendar table using start and end dates based on my data.Calendar = CALENDAR(MIN('Table'[StartDate]),MAX('Table'[EndDate]))
Then, I added a measure to the main table that gets the filtered values and applies the count and filtering criteria using the recommendations in this post. A DISTINCTCOUNT was enough but I wanted to be super safe.
In this measure, I'm getting the min and max values selected in the slicer and assigning them to variables. Then counting ids based on the required criteria applying conditions in the filter.Number of Projects = VAR MinDate = MIN ( 'Calendar'[Date] ) VAR MaxDate = MAX ( 'Calendar'[Date] ) RETURN CALCULATE( DISTINCTCOUNTNOBLANK(Table[Id]) ,FILTER( Table ,OR( AND( Table[StartDate] <= MinDate ,Table[EndDate] >= MinDate || Table[EndDate] = BLANK() ) ,AND( Table[StartDate] >= MinDate ,Table[StartDate] <= MaxDate ) ) ) )
Once all of this was set, all I had to do was to use the new measure for counts, it even worked like a charm after adding related tables to the model (watch out for relationship directionality).Thanks jdbuchanan71 for all your help, this is now working nicely
If the date table is joined to your fact table for some other reporting you can modify the measure like this.
Record_Count =
VAR MinDate = MIN ( DATES[Date] )
VAR MaxDate = MAX ( DATES[Date] )
RETURN
CALCULATE (
COUNTROWS ( YourTable ),
YourTable[Start Date] <= MaxDate,
YourTable[End Date] >= MinDate,
REMOVEFILTERS(Dates)
)
In this example you can see records getting a count when the start and end date fall outside the selected range:
I have attached my sample file for you to look at.