09.3Filter context
Let’s move on to the second question, “Which rows are visible?” Its answer is the filter context, the rows visible at the moment a measure is calculated. Let’s see who decides on these rows, and how.
09.3.1Several filters at once
In a Power BI report, several elements can hide rows at the same time:
- The row or the column of the visual, like the city.
- A slicer on the page.
- The Filters pane, for the visual, the page or the whole report.
- A click on another visual of the page.
These filters add up. A row stays visible only if it meets all of them.
Take the visual by city, with a on the category, set to Sedan. On the New York row of the visual:
- The New York row leaves only the 5 New York sales visible.
- Among them, the slicer keeps only the sedans. V001 and V006 remain.
- SUM adds up 250,000 and 200,000, and returns 450,000.
Try it yourself. Change the city in the visual, then the category in the slicer:
| City | Revenue |
|---|---|
| 450,000 | |
| 250,000 | |
| 150,000 | |
| 850,000 |
| Sale ID | Customer city | Category | Amount |
|---|---|---|---|
| V001 | New York | Sedan | 250,000 |
| V002 | New York | SUV | 150,000 |
| V003 | Chicago | Sedan | 100,000 |
| V004 | Chicago | City car | 100,000 |
| V005 | Toronto | Sedan | 150,000 |
| V006 | New York | Sedan | 200,000 |
| V007 | New York | SUV | 150,000 |
| V008 | New York | City car | 150,000 |
| V009 | Chicago | Sedan | 150,000 |
| V010 | Chicago | SUV | 150,000 |
| V011 | Toronto | SUV | 100,000 |
| V012 | Toronto | City car | 50,000 |
09.3.2The filter follows the relationship
The city is not a column of Sales. It is in the Customers table. How does Sales know which sales to hide?
Customers and Sales share a column, “Customer ID.” They are linked by a . On the New York row of the visual, the filter goes through this relationship:
- In Customers, only the New York customers remain visible, C001, C002 and C003.
- Through the Customer ID column, the filter passes into Sales.
- In Sales, only the sales of these three customers remain visible, V001, V002, V006, V007 and V008.
The filter on the category takes the same path, from the Products table, through the Product Code column.
The filter flows down from Customers to Sales, and from Products to Sales. Without any other setting, it does not flow back the other way. If a figure does not react to a filter, the formula is not necessarily to blame. First check the direction of the relationship, as the quiz of this lesson shows with COUNTROWS( Customers ).
09.3.3CALCULATE changes the filter context
CALCULATE, covered later, carries out a calculation after changing the filters. It can add a filter, or replace the one that exists on the same column.
Quiz
The questions often rely on the course tables. Keep them in view in their floating window, which you can move and enlarge.
Question 1
The visual by city has a slicer on the category, set to Sedan. What does the measure SUM( Sales[Amount] ) return on the Chicago row?
Question 2
The measure CALCULATE( SUM( Sales[Amount] ), Customers[City] = "New York" ) is placed in a visual by category. What does the City car row show?
Question 3
A visual by category shows the measure COUNTROWS( Customers ). What does the SUV row show?
- The visual, the slicers, the Filters pane and the other visuals filter at the same time. Their filters add up.
- A filter placed on Customers or Products flows down to Sales through the relationship. Without any other setting, it does not flow back the other way.
- CALCULATE adds a filter, or replaces the one that exists on the same column.