Sub topic 3
Filter context: evaluating over a filtered set of rows
This chapter assumes you can navigate Power BI Desktop, know what a star-schema model is, and can read basic DAX such as SUM and IF. It covers filter context, the context that measures use. The previous chapter covered row context, which calculated columns use.
What filter context is
Filter context is the set of filters that decides which rows of each table are visible when a formula runs. It is not a property of the formula. The report supplies it, and the same formula returns different results as that context changes.
Each of these adds filters:
- A row or column header in a table or matrix visual.
- A category on a chart axis or a legend.
- A slicer selection.
- A filter in the Filters pane, at visual, page or report level.
- A cross-highlight from clicking another visual.
Power BI combines all of them. A cell in a matrix that shows Red products in 2025 has a filter context of Color = Red and Year = 2025, plus any slicers on the page.
A measure reads the current filter context
Take this measure, which sums a stored column:
Total Sales = SUM(Sales[Line Amount])The formula has no filter written in it. Placed in a card with no filters, it returns the sum over every row of Sales. Placed in a matrix with Product Category on the rows, it runs once per category, and each run sees only that category's rows.
Filters travel along relationships. If Category is filtered on the Product table, the filter passes down the many-to-one relationship and reduces the Sales table to matching rows. This is why you can group Sales values by a column from a different table.
The next measure gives the same total without a stored column. SUMX creates a row context over the rows that the filter context leaves visible:
Total Sales (no column) = SUMX(Sales, Sales[Quantity] * Sales[Unit Price])The two contexts work in sequence. Filter context first selects the rows. Row context then steps through them one at a time inside SUMX.
Changing the filter context with CALCULATE
CALCULATE evaluates an expression under a modified filter context. This measure replaces any existing filter on Product Color with Red:
Red Sales = CALCULATE([Total Sales], Product[Color] = "Red")In a matrix by Color, the Blue row still shows the Red total, because CALCULATE overrides the Color filter that the row header supplied. Filters on other columns, such as Year, stay in place.
Why calculated columns do not use it
A calculated column is evaluated during data refresh, before any visual exists. No slicer or axis can affect it, so it has no report filter context. It sees only its own row. If you write SUM(Sales[Line Amount]) in a calculated column, you get the grand total on every row, because nothing restricts the rows. That result is rarely what you want.
Common errors
- Expecting a measure to return one fixed number. It returns a different number in every cell of a visual.
- Expecting a slicer to change a calculated column. The column was stored at refresh and does not respond.
- Forgetting that
CALCULATEreplaces a filter on the same column instead of adding to it.
Exercise
A matrix has Product Category on the rows and a slicer set to 2025. It shows the measure Total Sales = SUM(Sales[Line Amount]). What filters apply to the Bikes row, and where do they come from?
Show answer
Two filters apply. Category = Bikes comes from the row header, and Year = 2025 comes from the slicer. Power BI combines them into one filter context, and Total Sales sums Line Amount only for Sales rows that match both.
Exercise
In the matrix above, Red Sales = CALCULATE([Total Sales], Product[Color] = "Red") is added. What does the Bikes row show?
Show answer
The total for Red products in the Bikes category in 2025. CALCULATE replaces any Color filter, but the Category and Year filters stay.