Sub topic 1
How filter context shapes a measure's result
This chapter explains filter context, the set of filters that decides which rows a measure sees. Every later chapter builds on it. Once you can predict what filter context a cell has, you can predict what a measure returns there.
Prerequisites
This chapter assumes you already know:
- How to write basic DAX measures such as
SUMandCOUNTROWS. - What tables, columns, and relationships are in a Power BI or Analysis Services data model.
- How report visuals and slicers filter data.
The examples use a model with a Sales fact table and a 'Product' dimension table. Sales has the columns Amount, Quantity, and Net Price. 'Product' has Color and Category. A one-to-many relationship links 'Product' to Sales.
What filter context is
A measure is a formula that is evaluated again for every cell of a visual. The formula text stays the same, but the result changes from cell to cell. The reason is filter context.
Filter context is the set of filters active at the moment a measure is evaluated. It is a set of conditions on columns, such as 'Product'[Color] = "Red". Only rows that satisfy all of the conditions are visible to the measure.
Consider this base measure:
Total Sales = SUM ( Sales[Amount] )The formula never mentions product, color, or year. It still returns different numbers in different places, because each place applies different filters before SUM runs.
Where filters come from
Filter context is built from several sources, and they combine with AND logic.
| Source | Example | Effect |
|---|---|---|
| Rows of a table or matrix | A row for category "Bikes" | Filters `'Product'[Category]` to Bikes |
| Columns of a matrix | A column for year 2025 | Filters the year column to 2025 |
| Slicers | A slicer set to "Red" | Filters `'Product'[Color]` to Red |
| Visual, page, and report filters | A filter pane setting | Adds its condition to every cell it covers |
| Cross-filtering from other visuals | Clicking a bar in a chart | Filters the other visuals on the page |
If a matrix has Category on its rows and a slicer set to Red, the cell for Bikes has two filters: Category = Bikes and Color = Red. Total Sales there returns the sales of red bikes.
Filters travel through relationships
A filter on one table also reaches related tables. A filter on 'Product'[Category] flows along the relationship to Sales, so Sales shows only rows for products in that category. This is why SUM ( Sales[Amount] ) responds to a filter on a column of a different table.
By default, filters flow from the "one" side of a relationship to the "many" side. A filter on 'Product' reaches Sales, but a filter on Sales does not reach 'Product' unless you change the cross-filter direction.
A worked example
Suppose the following data is the whole Sales table, joined to 'Product'.
| Category | Color | Amount |
|---|---|---|
| Bikes | Red | 400 |
| Bikes | Blue | 300 |
| Helmets | Red | 100 |
| Helmets | Blue | 200 |
Here is what Total Sales returns in several cells.
| Where the measure is evaluated | Filter context | Result |
|---|---|---|
| Card visual, no slicer | None | 1000 |
| Matrix row "Bikes" | Category = Bikes | 700 |
| Matrix row "Helmets" | Category = Helmets | 300 |
| Card with Red slicer | Color = Red | 500 |
| Matrix row "Bikes" with Red slicer | Category = Bikes and Color = Red | 400 |
The measure definition did not change in any row of the table. Only the filter context did.
Why this matters for the rest of the tutorial
The functions in the title all work on filter context. CALCULATE changes it, FILTER produces a set of rows to use as a filter, and ALL, ALLEXCEPT, and REMOVEFILTERS clear some or all of it. Before using any of them, ask what the current filter context is, and what you want it to be.
Common errors at this stage
- Expecting a measure to return a fixed value. A measure always depends on its cell, so the same measure gives different results in a card, a matrix row, and a chart.
- Forgetting hidden filters. A page filter or a slicer you did not notice can explain a number that looks wrong.
- Forgetting the direction of relationships. A filter on
Salesdoes not reach'Product'with the default direction, so a measure on'Product'may not respond the way you expect.
Exercise
Using the example table above, a matrix has Color on its rows, and a slicer on 'Product'[Category] is set to Helmets. What does Total Sales return for the row "Blue"?
Show answer
200. The cell has two filters, Color = Blue from the matrix row and Category = Helmets from the slicer. Only the Helmets and Blue row of the data satisfies both, and its Amount is 200.
Exercise
A measure Total Sales = SUM ( Sales[Amount] ) is placed in a card visual with no slicers or filters. Which filter context applies, and what does the card show for the example data?
Show answer
The filter context is empty, so every Sales row is visible. The card shows 1000, the sum of all four Amount values.