Short answer: row context means "the current row": DAX knows which row it is on and can read that row's columns. It exists in two places: in a calculated column (each row in turn) and inside an iterator function such as SUMX, AVERAGEX, FILTER or ADDCOLUMNS (each row of the table you give it). Row context does not filter anything: a SUM inside it still sums the whole table. To follow a relationship use RELATED (to the one side) or RELATEDTABLE (to the many side); to turn the row into a filter, use CALCULATE.
Two contexts drive every DAX result: filter context (what the visual and slicers filter) and row context (which row an iteration is on). Mixing them up gives the classic puzzle: a calculated column = SUM(Sales[Amount]) shows the grand total on every row.
Where does row context come from?
- 1Calculated columnthe formula runs once per row of its table
- 2IteratorSUMX, AVERAGEX, MAXX, COUNTX, FILTER, ADDCOLUMNS, RANKX run the expression once per row
- 3InsideTable[Column] reads the current row's value
-- calculated column on Sales: row context from the column
Line Amount = Sales[Quantity] * Sales[Unit Price]
-- measure: row context from SUMX over Sales
Revenue = SUMX ( Sales, Sales[Quantity] * Sales[Unit Price] )A measure has no row context of its own: Sales[Quantity] alone in a measure is an error ("a single value for column cannot be determined"), because there is no current row.
Why does SUM in a column give the grand total?
-- calculated column on Customer
Customer Sales Wrong = SUM ( Sales[Amount] )
Customer Sales Right = CALCULATE ( SUM ( Sales[Amount] ) )
Customer Sales Also Right = SUMX ( RELATEDTABLE ( Sales ), Sales[Amount] )| Customer | Customer Sales Wrong | Customer Sales Right |
|---|---|---|
| Ana | 12,400 | 3,100 |
| Ben | 12,400 | 7,800 |
| Chen | 12,400 | 1,500 |
The row context on Customer says "the current customer is Ana", but it filters nothing, so SUM sees all of Sales. CALCULATE performs context transition: the current row becomes a filter (Customer = Ana), which flows through the relationship to Sales. RELATEDTABLE returns Ana's sales rows directly.
How do RELATED and RELATEDTABLE work?
Row context can follow relationships in a direction:
| Function | From | Returns |
|---|---|---|
RELATED ( Product[Category] ) | a row on the many side (Sales) | the one matching value on the one side |
RELATEDTABLE ( Sales ) | a row on the one side (Customer) | the table of matching rows on the many side |
-- on Sales: the category of each line's product
Category = RELATED ( 'Product'[Category] )
-- measure: revenue at list price, reading the product's list price per line
Revenue at List =
SUMX ( Sales, Sales[Quantity] * RELATED ( 'Product'[List Price] ) )What about nested row contexts?
Iterators can be nested; each adds a row context. An inner reference to the same table sees the inner row. To reach the outer row, store it in a variable first (older formulas used EARLIER):
-- calculated column on Product: rank by list price within the category
Price Rank in Category =
VAR ThisCategory = 'Product'[Category]
VAR ThisPrice = 'Product'[List Price]
RETURN
COUNTROWS (
FILTER (
'Product',
'Product'[Category] = ThisCategory
&& 'Product'[List Price] > ThisPrice
)
) + 1Inside FILTER, 'Product'[Category] is the inner row; ThisCategory holds the outer one. See EARLIER and EARLIEST for the older form.
What does it cost?
An iterator runs its expression once per row. SUMX ( Sales, ... ) over 50 million rows is fast when the expression is simple column math, because the storage engine does it in bulk. It gets slow when each row calls a measure (a context transition per row) or FILTER over a whole large table. Iterate the smallest table that gives the right answer: SUMX ( VALUES ( Customer[Customer] ), [Revenue] ) iterates customers, not sales lines.
What goes wrong?
- Aggregates in a column without CALCULATE. They ignore the row; wrap them in
CALCULATEor useRELATEDTABLE. - A column reference in a measure without an iterator. No row context: use an aggregate or an iterator.
- RELATED the wrong way.
RELATEDgoes to the one side only; from the one side useRELATEDTABLE. - Measures inside large iterators. Each call is a context transition; iterate a smaller table.
Where can you check this?
- Microsoft Learn: DAX overview (context)
- Microsoft Learn: RELATED function (DAX)
- Microsoft Learn: RELATEDTABLE function (DAX)
Where do you start?
Write Customer Sales Wrong and Customer Sales Right side by side in a test model and look at the difference. Then read filter context and context transition, the other half of DAX.