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
Thank you so much, this is a very nice, simple way to make it work, I really appreciate your insight!
I tried to use this solution you described, it matches my data model perfectly, and I came to an error that I don't understand the root cause for.
The measure I ended up using is similar to the one you posted but it adds a few conditions:
The weird thing is that I have an unfiltered distinct count of row ids of 313 if I only add locations and 316 if I count statuses and if I mix them in a matrix pivot-table style, the count goes down to 302. The model is very simple, there is only one table with all the data and I am not applying any other filters for the status and location columns. Also, if I leave the filter by measure aside, the count is 316 for both columns. Would you know why this might be happening?
Huge thanks again!
You should only need to check the start date vs the max date and the end date vs the min date like this.
DateFilterCount =
VAR MinDate = MIN ( 'Calendar'[Date] )
VAR MaxDate = MAX ( 'Calendar'[Date] )
RETURN
CALCULATE (
COUNTROWS ( Main ),
Main[StartDate] <= MaxDate,
Main[EndDate] >= MinDate
)
- arielschapiro4 years agoRegular Visitor
Thank you, that is a really good point! Unfortunately it didn't solve the count differences. I really appreciate it!