1.4.1. Row Context and Filter Context
💡 First Principle: Row context answers "which row am I on?" and filter context answers "which rows are visible?" Calculated columns live in row context; measures live in filter context. Knowing which one you're in tells you whether a formula can reference "this row's value" or must aggregate.
Row context exists automatically in calculated columns: the formula Sales[Quantity] * Sales[UnitPrice] evaluates once per row, reading that row's values. Row context also exists inside iterator functions, the "X" functions such as SUMX, AVERAGEX, and COUNTX, which walk a table row by row, evaluate an expression for each row, then aggregate. SUMX(Sales, Sales[Quantity] * Sales[UnitPrice]) computes revenue per row and sums the results, all inside a measure, without storing a column.
Filter context is the set of filters active when a measure is evaluated: from slicers, the filter pane, visual row and column headers, and CALCULATE modifiers. A measure such as SUM(Sales[SalesAmount]) has no notion of "the current row"; it sums whatever rows survive the filter context. In a matrix with Category on rows and Year on columns, each cell gets its own filter context (this category, this year), and the total row gets a context with the category filter removed.
| Aspect | Row context | Filter context |
|---|---|---|
| Question it answers | Which single row is being evaluated? | Which rows are visible? |
| Created by | Calculated columns, iterators (SUMX, FILTER, ADDCOLUMNS) | Slicers, filters, visual axes, CALCULATE |
| Typical object | Calculated column | Measure |
| Can read a column value directly | Yes, the current row's value | No, must aggregate |
| Propagates through relationships | No, not on its own | Yes, from one side to many side |
The two contexts meet through context transition: when a measure (or CALCULATE) is evaluated inside a row context, the current row is converted into an equivalent filter context. That's why referencing a measure inside a calculated column on Customer returns that customer's sales rather than the grand total. You'll use this deliberately in 3.2.2.
⚠️ Exam Trap: A calculated column is evaluated at refresh and doesn't recalculate when a user clicks a slicer. If a stem requires a value that changes with user selections (a percentage of the selected total, a rank within the filtered set), the answer must be a measure.
Reflection Question: A calculated column on the Product table defined as SUM(Sales[SalesAmount]) returns the same grand total on every row, but [Total Sales] (a measure containing that same SUM) used in the same column returns each product's own sales. Explain the difference using row context, filter context, and context transition.