Forum Discussion
Help with dynamic filtering
- 3 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
It is an interaction of the blank [End Date] field when looking at the view by Status. Try changing the measure to this.
DateFilterCount =
VAR MinDate = MIN ( 'Calendar'[Date] )
VAR MaxDate = MAX ( 'Calendar'[Date] )
RETURN
CALCULATE (
COUNTROWS (Main)
,Main[Start Date] <= MaxDate,
( Main[End Date] >= MinDate || Main[End Date] = BLANK() )
)
I think I figured out the problem (very strange one). I added the measure for the count and realized it is coherent across all tables but if I count the ids row it is not. I can't make sense of this behavior but it seems like using the measure instead of the ids for counting solves the problem. I'd appreciate any other insights you might have but I know it's probably not obvious.
Huge thanks again, you have been of great help!