Forum Discussion
Problem with a date filter
- Anonymous4 years ago
Hi jsteffe ,
Slicer just filters the data of the columns in the connexions table, but the measure will not be changed by the selection of the slicer
You can use Flag to filter the date, only the date selected by the slicer is displayed in Visual
Here are the steps you can follow:
1. Create measure.
Flag = var _min=MIN('Calendar'[Date]) var _max=MAX('Calendar'[Date]) return IF( MAX('connexions'[lastConnexionDate])>=_min&&MAX('connexions'[lastConnexionDate])<=_max,1,0)2. Place [Flag]in Filters, set is=1, apply filter.
3. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Ok, that's really made me think. Hoping Greg_Deckler, marcorusso or AlbertoFerrari can confirm my conclusion.
I reduced it down as far I could to remove any issues I could think of and looked at the result query from the table in DAX studio. That included creating a very basic date table (NewDate) and replacing your status measure so it simply returns 1 regardless. Tidied up query in DAX Studio as follows:
DEFINE
VAR DateFilterTable =
FILTER(
VALUES('NewDate'[Date]),
'NewDate'[Date] < DATE(2022, 1, 26)
)
VAR ResultTable =
SUMMARIZECOLUMNS(
'connexions'[lastConnexionDate],
DateFilterTable,
"status", 1
)
EVALUATE
ResultTable
ORDER BY
'connexions'[lastConnexionDate] DESC
Even in this simplified state you still get the same issue:
Going back to the definition of SUMMARIZECOLUMNS which is what PowerBi uses in the background for that visual there's the following statement:
"Filters in SUMMARIZECOLUMNS only apply to group-by columns from the same table and to measures. They do not apply to group-by columns from other tables directly, but indirectly through the implied non-empty filter from measures. In order to apply a filter to the group-by column unconditionally, apply the filter through a CALCULATETABLE function that evaluates SUMMARIZECOLUMNS."
In short because you're grouping by the date column in your fact table the filter from the date table has no effect. In fact it never did however it looked like it was because your original measure was returning blank. (Note the line "indirectly through the implied non-empty filter from measures").
In order to fix it you need to use the date column from your date table in the visual and then I suspect may have to tweak your original measure to turn it around.
You are correct, nice diagnosis.
SUMMARIZECOLUMNS is likely to be the king of DAX shenanigans, the one you depicted is one of the nicest.