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.
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?
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.
- PaulDBrown5 years agoCommunity Champion
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.
- Anonymous5 years agoNot applicable
PaulDBrown Ok so we remove the filter on the week column (and all table columns because it references the table in its entirety) which allows for the exposure of all weeks in the data table. But because we're using the max function, it refers to the slicer for the filter reference.
I guess then why is the slicer being used as a filter reference and not the max week in the table (52) without the filter? Why does the slicer come back into play? If we wanted to remove the role of the slicer, what would you do differently?
Thank you for this recommendation - it'llhelp me break the problem down moving forward:
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") of the table.
- PaulDBrown5 years agoCommunity Champion
Anonymous
The slicer comes back into play because the filter expression refers to the column (Date [Week Number]) used in the slicer
The easiest way to ignore a slicer is to remove the visual interaction under Format in the ribbon, "Edit interactions". (But this will affect all the measures in the visual)
You can of course ignore a slicer selection by simply using ALL by itself in the filter expression: if you reference a Table, it removes all filters from that table; if you reference a column, it removes any filter applied to that column
- Anonymous5 years agoNot applicable
PaulDBrown you must frequently hit your head off a table in frustration dealing with learners like me!
"The slicer comes back into play because the filter expression refers to the column (Date [Week Number]) used in the slicer" - so our ALL function never removes the role of the slicer, it unfilters the data table but the slicer is still 'alive' so when filter expressions are used it filters with the slicer again?
- PaulDBrown5 years agoCommunity Champion
Anonymous
Correct. The ALL function removes a specified filter on a table/column (it doesn't "erase" a filter)
The filtered column ("Slicer") comes into play again because the filter expression explicitly refers to that column. In this case, the MAX function is returning the selected value in the filtered column ("Slicer").
- Anonymous5 years agoNot applicable
Sorry Paul, this is the bit that still doesnt add up:
The filtered column ("Slicer") comes into play again because the filter expression explicitly refers to that column - this column shouldnt have a filter now though because 'ALL' removed it. This specific issue is what's causing the confusion for me.
Sorry if you've already answered this in a different way previously.
- Anonymous5 years agoNot applicable
Thank you PaulDBrown and CNENFRNL , truly appreciated your help!