Sub topic 3
How Filters Change a Measure's Result
This chapter assumes you can work in Power BI Desktop's Report view and Fields pane, and that you have a Sales table with a numeric SalesAmount column. It also assumes you have created a measure such as Total Sales = SUM(Sales[SalesAmount]). The chapter explains why that one formula returns different numbers in different places on a report.
The core idea: a measure is evaluated per cell
A measure does not store a number. It stores a formula. Power BI evaluates that formula each time it has to show a value, and it evaluates it once for every cell, bar, card, or data point in a visual.
Before each evaluation, Power BI works out which rows of the data model are visible to that cell. The set of visible rows is called the filter context. The formula then runs against only those rows.
This is why one measure can show 1.2 million on a card, 300,000 for "Bikes" in a table row, and 45,000 for "Bikes in 2024" in a matrix cell. The formula is the same each time. The filter context is different.
Where filter context comes from
Several parts of a report each add filters. They combine, and a row must pass all of them to be visible to the measure.
| Source | Example | Effect |
|---|---|---|
| Row or column fields in a visual | Product Category on the rows of a table | Each row evaluates the measure for one category only |
| Axis and legend fields | Month on a chart's X-axis | Each bar evaluates the measure for one month |
| Slicers | A Year slicer set to 2024 | Every visual on the page sees only 2024 rows |
| Visual-level filters | Region is "West" in the Filters pane | Only that visual is limited to the West |
| Page-level filters | Status is not "Cancelled" | All visuals on that page exclude cancelled rows |
| Report-level filters | Year is 2023 or later | All pages exclude older rows |
| Cross-filtering by clicking | Clicking a bar in one chart | Other visuals on the page filter to that selection |
A field being placed in a visual is a filter, even though it does not look like one. If you put Product Category in the rows of a table, each row of the table gets its own filter context with one category selected.
A worked example
Suppose the Sales table looks like this.
| OrderID | Category | Year | Region | SalesAmount |
|---|---|---|---|---|
| 1001 | Bikes | 2023 | West | 1,200 |
| 1002 | Bikes | 2024 | West | 1,500 |
| 1003 | Helmets | 2024 | East | 80 |
| 1004 | Helmets | 2024 | West | 95 |
| 1005 | Bikes | 2024 | East | 900 |
You have these measures:
Total Sales = SUM(Sales[SalesAmount])Order Lines = COUNTROWS(Sales)The next table shows what each measure returns under different filter contexts.
| Filter context | Rows visible | Total Sales | Order Lines |
|---|---|---|---|
| None (a card on its own) | 1001–1005 | 3,775 | 5 |
| Category = Bikes | 1001, 1002, 1005 | 3,600 | 3 |
| Category = Helmets | 1003, 1004 | 175 | 2 |
| Year = 2024 | 1002, 1003, 1004, 1005 | 2,575 | 4 |
| Category = Bikes and Year = 2024 | 1002, 1005 | 2,400 | 2 |
| Category = Helmets and Region = West | 1004 | 95 | 1 |
Check the third row by hand. Bikes has three rows, 1,200 + 1,500 + 900 = 3,600. The measure did not change. Only the rows it could see changed.
Seeing filter context in a visual
Build a table visual and add Category to it, then add Total Sales and Order Lines. Power BI evaluates each measure once per category row and once more for the total row.
The total row is not the sum of the displayed rows. It is a separate evaluation with no category filter. For SUM and COUNTROWS the two happen to agree, because every row belongs to exactly one category. That agreement breaks for other kinds of measures, so do not rely on it. A ratio is the most common case.
Slicers and the whole page
Add a Year slicer to the page and select 2024. Every visual on the page now carries a Year = 2024 filter in addition to its own fields. The table visual from above now shows these numbers.
| Category | Total Sales | Order Lines |
|---|---|---|
| Bikes | 2,400 | 2 |
| Helmets | 175 | 2 |
| Total | 2,575 | 4 |
The Bikes row dropped from 3,600 to 2,400 because row 1001 (2023) is no longer visible. You did not edit the measure. You changed the context.
If you select two years in the slicer, the slicer filter keeps rows matching either year. Filters from the same field combine with "or". Filters from different fields combine with "and".
Filters and ratios
Ratio measures show the effect of filter context clearly, because both parts of the ratio change together. Consider this measure built from the two above.
Average Sales per Order Line = DIVIDE([Total Sales], [Order Lines])Under Category = Bikes, the numerator is 3,600 and the denominator is 3. The result is 1,200. Under Category = Helmets, it is 175 divided by 2, which is 87.5. With no filter it is 3,775 divided by 5, which is 755.
The total row of the table shows 755. It does not show the average of 1,200 and 87.5, which would be 643.75. The total row is a fresh evaluation with all rows visible. This is correct behavior, and a common source of confusion when people compare a total to an average of the rows above it.
Filter context can also make a denominator empty. Select Category = Helmets and Year = 2023. No rows are visible. Order Lines returns 0 for COUNTROWS of an empty set, and Total Sales returns BLANK. DIVIDE handles this case without an error, which later chapters cover.
Empty contexts: BLANK versus zero
When no rows are visible, the two measures behave differently.
| Measure | Result with no visible rows |
|---|---|
| `SUM(Sales[SalesAmount])` | BLANK |
| `COUNTROWS(Sales)` | 0 |
Power BI hides rows where all the measures in a table visual are BLANK. A category with no sales in the selected year may therefore disappear from a table that shows only Total Sales. It stays visible if the table also includes Order Lines, because that measure returns 0, which is not blank. If a category vanishes unexpectedly after you add a slicer, this is a likely cause.
Filters apply to the table, and related tables follow
A filter on one table can reach another table through a relationship. If a Product table relates to Sales, and you slice by Product[Category], the filter travels from Product to Sales along the relationship. The Sales rows that match the selected products remain visible, and SUM(Sales[SalesAmount]) adds only those.
The direction matters. By default, filters flow from the "one" side of a relationship (for example, Product) to the "many" side (Sales). A slicer on Sales[Region] will not narrow a list of products by default.
Common mistakes
- Expecting a measure to change when it should not. A measure respects every filter in scope. If a card shows a lower number than expected, check slicers, page filters, and report filters in the Filters pane before changing the formula.
- Comparing the total row to the visible rows. The total row is its own evaluation. Do not assume it equals the sum or average of the rows above.
- Using a column field where a measure belongs. Dragging SalesAmount directly into a visual creates an implicit aggregation. A measure gives you a named, reusable formula. Later chapters explain why explicit measures are better.
- Testing a measure in one visual only. Check it in a card, in a table split by a category, and with a slicer applied. If the numbers follow the logic of the worked example above, the measure is behaving as intended.
- Forgetting that filters combine. A visual-level filter, a page filter, and a slicer all apply at once. Rows must satisfy all of them.
Checking filter context yourself
You can see context at work without writing new DAX. Use this routine on any measure.
- Place the measure in a card. Note the value. This is the value for whatever page and report filters apply.
- Convert the card to a table and add a column such as Category. Check that the rows make sense compared with the card.
- Add a slicer for another field, such as Year. Select one value and watch every number change.
- Clear the slicer, then use the Filters pane to add a visual-level filter. Compare the result.
- Hover over a table cell, or use the "Show data point as a table" option in the visual's menu, to inspect the numbers that feed it.
When a number looks wrong, ask which filters are active in that cell. The answer is almost always found in that list.
Filtering inside a measure
Slicers and visuals are not the only way to restrict rows. A measure can also build its own restricted table. The example below counts only rows where SalesAmount is greater than 1000.
Large Order Lines = COUNTROWS(FILTER(Sales, Sales[SalesAmount] > 1000))This formula still respects the outside filter context. FILTER(Sales, ...) starts from the Sales rows visible in the current cell, then keeps those over 1,000. With Category = Bikes in the table above, the visible rows are 1001, 1002, and 1005. Rows 1001 and 1002 pass the test, so the result is 2. A later chapter covers this pattern in more detail.
Summary of the model
- A measure is a stored formula, evaluated again for every cell.
- Before each evaluation, Power BI builds a filter context from the visual's fields, slicers, and filters at visual, page, and report level.
- The formula runs only on the rows that survive that context.
- Filters from different fields combine with "and". Filters from one field combine with "or".
- The total row is a separate evaluation with fewer filters, not a sum of the rows.
- Filters travel across relationships, from the "one" side to the "many" side by default.
Exercise
A table visual shows Category rows with Total Sales and Order Lines, and a Year slicer is set to 2023. Using the Sales table in this chapter, what are Total Sales and Order Lines for the Bikes row? Then say what the Helmets row would show if the table contained only Total Sales.
Show answer
With Year = 2023, only row 1001 is visible for Bikes, so Total Sales is 1,200 and Order Lines is 1. No Helmets rows exist in 2023. Total Sales returns BLANK for Helmets, and if the table contains only Total Sales, Power BI hides the Helmets row because all of its measures are blank. If Order Lines were also in the table, Helmets would still appear with Order Lines equal to 0.
Exercise
The table total for Average Sales per Order Line shows 755, but the two category rows show 1,200 and 87.5. A colleague says the total is wrong because the average of those two numbers is 643.75. How do you respond?
Show answer
The total is correct. The total row is evaluated with no category filter, so the formula divides all sales (3,775) by all order lines (5) to get 755. Averaging the two category results would give each category equal weight, even though Bikes has three order lines and Helmets has two. The measure answers "average sales per order line across all visible rows", and that is 755.
Exercise
You add a slicer built from a Region column in a separate table that has no relationship to Sales. You select "West", and Total Sales does not change. Why, and what should you check?
Show answer
Filters reach a measure only through the table it reads or through relationships to that table. With no relationship, the Region selection never filters the Sales rows, so every value stays the same. Check the model view for a relationship between the two tables, confirm it is active, and confirm it points in a direction that lets the filter flow to Sales.