09.1Two contexts, two questions
Before calculating, DAX has to know what it is calculating on. To find out, it asks itself two questions. If you use Excel, you already know them.
09.1.1Which row am I on?
In Excel, you often write a formula in a column, then copy it down. In D2, the formula =B2C2 multiplies the values of row 2. Copied to D3, it becomes =B3C3. Each row uses its own values.
DAX does the same thing in the Sales table. Suppose its Amount column does not exist yet. You add it like this:
There is no row number here. Sales[Qty] is the name of the whole column, which has 12 quantities. Yet DAX knows which one to take, because it calculates the formula on one row at a time. Step through it yourself:
| 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 |
On the V001 row, Sales[Qty] is 10 and Sales[Price] is 25,000. The formula returns 250,000. On the V002 row, it returns 3 × 50,000, that is 150,000.
The row on which DAX is calculating is called the . It answers the question “which row am I on?”
09.1.2Which rows are visible?
In Excel, you can also filter a table, for example to keep only New York. The other rows are hidden. The SUBTOTAL function then adds up only the visible rows.
A measure works the same way. Take this one, placed in a table visual by city:
In a visual with one row per city, the measure is calculated once for each row of the visual. On the New York row, only the 5 sales of the New York customers remain visible. SUM adds up their amounts and returns 900,000. The other 7 sales are hidden, as in a filtered Excel table.
Click another city in the visual, then the “Total” row:
| City | Revenue |
|---|---|
| 900,000 | |
| 500,000 | |
| 300,000 | |
| 1,700,000 |
| Sale ID | Customer city | Category | Amount |
|---|---|---|---|
| V001 | New York | Sedan | 250,000 |
| V002 | New York | SUV | 150,000 |
| V003 | Chicago | Sedan | 100,000 |
| V004 | Chicago | City car | 100,000 |
| V005 | Toronto | Sedan | 150,000 |
| V006 | New York | Sedan | 200,000 |
| V007 | New York | SUV | 150,000 |
| V008 | New York | City car | 150,000 |
| V009 | Chicago | Sedan | 150,000 |
| V010 | Chicago | SUV | 150,000 |
| V011 | Toronto | SUV | 100,000 |
| V012 | Toronto | City car | 50,000 |
On the “Total” row, nothing is hidden anymore. SUM adds up the 12 sales.
The rows visible at the time of the calculation form the . It answers the question “which rows are visible?”
09.1.3The two questions side by side
The two contexts do not answer the same question.
- The row context points to a single row, the current one. It is the Excel formula copied down. You find it, for example, in a calculated column.
- The filter context points to several rows, the visible ones. It is the filtered Excel table. You find it, for example, in a measure placed in a visual.
Later, other lessons look at each context closely, then at both together.
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 visual by city, on the Chicago row, which sales does the measure SUM( Sales[Amount] ) add up?
Question 2
In the Sales table, what does the calculated column Amount = Sales[Qty] * Sales[Price] return on the V008 row?
Question 3
In the visual by city, what does the measure SUM( Sales[Qty] ) return on the Toronto row?
- The row context is the row where DAX stands. In the Amount column, DAX stands on V001, reads 10 and 25,000, writes 250,000, then moves down to V002.
- The filter context is the set of rows the formula sees. On the Chicago row of the visual, Sales shows only V003, V004, V009 and V010. SUM adds up only these four sales.