09.2Row context
You have met the first question, “Which row am I on?” Its answer is the row context, the row on which DAX is calculating. Let’s see how DAX moves from one row to the next, where you find it, and what it does not do.
09.2.1One row after another
Let’s go back to the Amount column, added to the Sales table like this:
DAX does not calculate the column in one go. It calculates it one row after another, from top to bottom. On the V001 row, it multiplies 10 by 25,000 and writes 250,000. Then it moves to the V002 row, and so on down to V012. Follow it:
| Sale ID | Date | Customer ID | Product Code | Qty | Price | Amount |
|---|---|---|---|---|---|---|
| V001 | 1/15/2024 | C001 | A101 | 10 | 25,000 | |
| V002 | 3/8/2024 | C002 | A202 | 3 | 50,000 | |
| V003 | 5/20/2024 | C004 | A201 | 4 | 25,000 | |
| V004 | 9/12/2024 | C005 | A102 | 10 | 10,000 | |
| V005 | 11/25/2024 | C006 | A201 | 6 | 25,000 | |
| V006 | 1/10/2025 | C001 | A101 | 8 | 25,000 | |
| V007 | 2/18/2025 | C003 | A202 | 3 | 50,000 | |
| V008 | 3/27/2025 | C002 | A102 | 15 | 10,000 | |
| V009 | 5/6/2025 | C004 | A201 | 6 | 25,000 | |
| V010 | 7/14/2025 | C005 | A202 | 3 | 50,000 | |
| V011 | 9/30/2025 | C007 | A202 | 2 | 50,000 | |
| V012 | 12/2/2025 | C006 | A102 | 5 | 10,000 |
The table has 12 rows, so the formula is calculated 12 times.
Sales[Qty] and Sales[Price] thus return the quantity and the price of each row. In a row context, a column returns its value for each row.
09.2.2In FILTER too
A calculated column is not the only case where DAX moves from one row to the next. FILTER does it too.
FILTER keeps the rows of a table that meet a condition. To know whether a row meets the condition, it examines it. So it examines each row, one after another.
On the V001 row, Sales[Amount] is 250,000, more than 150,000. The row is kept. On the V002 row, it is 150,000, which is not greater than 150,000. The row is dropped. Follow FILTER over the 12 rows:
| Sale ID | Date | Customer ID | Product Code | Qty | Price | Amount | More than 150,000? |
|---|---|---|---|---|---|---|---|
| V001 | 1/15/2024 | C001 | A101 | 10 | 25,000 | 250,000 | |
| V002 | 3/8/2024 | C002 | A202 | 3 | 50,000 | 150,000 | |
| V003 | 5/20/2024 | C004 | A201 | 4 | 25,000 | 100,000 | |
| V004 | 9/12/2024 | C005 | A102 | 10 | 10,000 | 100,000 | |
| V005 | 11/25/2024 | C006 | A201 | 6 | 25,000 | 150,000 | |
| V006 | 1/10/2025 | C001 | A101 | 8 | 25,000 | 200,000 | |
| V007 | 2/18/2025 | C003 | A202 | 3 | 50,000 | 150,000 | |
| V008 | 3/27/2025 | C002 | A102 | 15 | 10,000 | 150,000 | |
| V009 | 5/6/2025 | C004 | A201 | 6 | 25,000 | 150,000 | |
| V010 | 7/14/2025 | C005 | A202 | 3 | 50,000 | 150,000 | |
| V011 | 9/30/2025 | C007 | A202 | 2 | 50,000 | 100,000 | |
| V012 | 12/2/2025 | C006 | A102 | 5 | 10,000 | 50,000 |
Only V001 and V006 are kept. FILTER returns a table of 2 rows.
09.2.3It hides no row
Excel helps again. In D2, the formula =SUM(C2:C13) adds up the 12 rows of the range. It is written on row 2, but it is not limited to row 2.
DAX works the same way. Let’s add this calculated column to the Sales table:
Total = SUM( Sales[Amount] )| Sale ID | Amount | Total |
|---|---|---|
| V001 | 250,000 | 1,700,000 |
| V002 | 150,000 | 1,700,000 |
| V003 | 100,000 | 1,700,000 |
| V004 | 100,000 | 1,700,000 |
| V005 | 150,000 | 1,700,000 |
| V006 | 200,000 | 1,700,000 |
| V007 | 150,000 | 1,700,000 |
| V008 | 150,000 | 1,700,000 |
| V009 | 150,000 | 1,700,000 |
| V010 | 150,000 | 1,700,000 |
| V011 | 100,000 | 1,700,000 |
| V012 | 50,000 | 1,700,000 |
This is a reproduction of the Power BI interface for teaching purposes. It differs from the real interface.
On the V001 row, you might think SUM adds up only 250,000. Yet it adds up the whole column, and the column shows 1,700,000 on every row. In a calculated column, SUM therefore adds up the whole column, whatever the row.
The row context only says which row you are on. It hides no row. SUM always sees the 12 amounts.
Quiz
The questions often rely on the course tables. Keep them in view in their floating window, which you can move and enlarge.
Question 1
In the Sales table, you add the calculated column Share = Sales[Amount] / SUM( Sales[Amount] ). What is its value on the V001 row?
Question 2
On a card with no filter at all, what does the measure COUNTROWS( FILTER( Sales, Sales[Amount] >= AVERAGE( Sales[Amount] ) ) ) return?
Question 3
In the Sales table, you add the calculated column Count = COUNTROWS( Sales ). What is its value on the V005 row?
- DAX calculates a calculated column one row after another. FILTER also looks at each row, one after another.
- In a row context, a column like Sales[Amount] returns its value for each row.
- The row context hides no row. In a calculated column, SUM therefore adds up the whole column.