Sub topic 1
How Filter Context Shapes a Measure's Result
Prerequisites
Assume you know basic DAX measures, tables, columns, relationships, and how slicers and visuals filter a Power BI model.
Filter Context Shapes a Measure's Result
Filter context is the set of filters active when a measure is evaluated. It comes from slicers, visual rows and columns, page filters, and filters supplied by DAX. The same measure can return different results because its context changes.
Total Sales = SUM ( Sales[Amount] )In a table grouped by Product[Category], this measure sums only the sales rows related to the current category. A slicer for year adds another filter.
| Visual context | Rows included by `[Total Sales]` |
|---|---|
| Category = Bikes, Year = 2025 | Sales related to Bikes in 2025 |
A measure usually reads filter context automatically. You change that context with CALCULATE.
flowchart TD
A[Slicer and visual filters] --> B[Filter context]
B --> C[Evaluate measure]
D[CALCULATE filters] --> B
C --> E[Result]Row Context and Iterators in Brief
Row context means DAX is working with one row at a time. It appears in calculated columns and in iterator functions such as FILTER, SUMX, and AVERAGEX. An iterator evaluates an expression separately for each row in a table.
Row context alone does not automatically filter a measure. CALCULATE can perform context transition, turning the current row into equivalent filters when needed.
CALCULATE: Changing Filter Context with Filter Arguments
CALCULATE evaluates an expression after modifying its filter context. A boolean filter argument tests a column directly:
Red Sales =
CALCULATE (
[Total Sales],
'Product'[Color] = "Red"
)This measure evaluates [Total Sales] for red products. By default, a filter on the same column is replaced. Other active filters, such as year or region, remain.
A table filter argument supplies rows to use as filters:
Large Line Sales =
CALCULATE (
[Total Sales],
FILTER ( Sales, Sales[Quantity] * Sales[Net Price] > 1000 )
)FILTER: Returning Matching Rows
FILTER returns a table containing only rows for which its condition is true. It is useful when the condition combines columns or depends on row-by-row calculations.
Exercise
Why can [Total Sales] return different values in two visuals?
Show answer
Each visual supplies a different filter context, so the measure sums different related Sales rows.