Forum Discussion
Why does this formula work? Filter(all(...
- 5 years ago
Anonymous
Yes, I know it is confusing...It takes a while to get your head around it (I've been at this for over 3 years and I learn stuff every day!).
We are back to a previous stage in the explanation. The whole FILTER expression contains 2 parts:
1) ALL removes the filters from the date table
2) THEN the second filter expression kicks in. What it's doing is seeing an unfiltered dates table (since ALL has removed the filters), and then it returns the values established in the second expression over the whole dates table. Since the second filter expression checks the week number column, which does have a value "selected", it applies the new filter based on that selected value.
Your second expression refers to the value selected in the week number column and a year. So it applies the filters accordingly over the whole date table.
Anonymous It seems to me that you didn't wrap your head around the order of calculation here. For FILTER func,
- it evaluates in the first place ALL('Date'), the full table of 'Date'
- secondly all those filtering criteria, i.e. 'Date'[Week Number]<=max('Date'[Week Number]) && 'Date'[Week Year]= max('Date'[Week Year]) is applied to full 'Date' table.
Thanks for the swift response. Sorry if i'm being dense but surely this means that by clearing the filters from my table it provides the full list of weeks, not just those filtered in the slicer?
- it evaluates in the first place ALL('Date'), the full table of 'Date' - so it removes the slicer filter which filtered to week 5
- secondly all those filtering criteria, i.e. 'Date'[Week Number]<=max('Date'[Week Number]) && 'Date'[Week Year]= max('Date'[Week Year]) is applied to full 'Date' table. and therefore it should bring back week 1 to 52 as there are 52 weeks in the table
?
- PaulDBrown5 years agoCommunity Champion
Anonymous
The logic follows the order you have stated. What seems to be confusing you is the MAX function used in the second expression. MAX will return the "max" value in the filter context. So if the filter context is one date/week/year, it returns THAT value. Think of it as acting like SELECTEDVALUE. (you can in fact use SELECTEDVALUE instead of MAX).
- Anonymous5 years agoNot applicable
Thank you both for your patience. Day 3 of Power BI and my head is melting. So my misunderstanding is where filter context applies.
So max returns 5 because the filter context is set by the slicer which is set to week 5. Can i ask why the filter context is not 52 at this point because ALL is executed first thereby removing the slicer filter context? Why is the filter context still 5?
- PaulDBrown5 years agoCommunity Champion
Anonymous
Think of it this way:
By using ALL, you remove the filters on the table/column specified. By adding the filter expression, you are now specifying or adding a new filter on the dates table determined by the expressions therein. A bit like "firstly remove the filter on the dates table and now apply this filter instead".
Again, the MAX function is acting like SELECTEDVALUE. So it "looks" at the slicer (which you have referenced in the filter expression), sees week 5, and establishes that value as the reference for the new filter expression.Something I tend to do to see what's going on is set up a table visual with the filtered column and the measure. You can then see what the measure returns for each filter context ("row", though you should never think of it as an Excel type row if you are using the column in a visual; the concept of "row" in the Excel sense is ONLY applicable in the context of a Data/Dimension table in the model) of the table.
- CNENFRNL5 years agoCommunity Champion
Anonymous
- it evaluates in the first place ALL('Date'), the full table of 'Date' - so it removes the slicer filter which filtered to week 5 - Yes, that's right
- secondly all those filtering criteria, i.e. 'Date'[Week Number]<=max('Date'[Week Number]) && 'Date'[Week Year]= max('Date'[Week Year]) is applied to full 'Date' table. and therefore it should bring back week 1 to 52 as there are 52 weeks in the table - max('Date'[Week Number]) returns the week number in the slicer, i.e. week 5, coz it's subject to filter context