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:

Amount = Sales[Qty] * Sales[Price]
Power BI accepts this DAX forno, Measureyes, Calculated columnno, Calculated tableno, Virtual table

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:

DAX calculates the Amount column
Sale IDDateCustomer IDProduct CodeQtyPriceAmount
V0011/15/2024C001A1011025,000
V0023/8/2024C002A202350,000
V0035/20/2024C004A201425,000
V0049/12/2024C005A1021010,000
V00511/25/2024C006A201625,000
V0061/10/2025C001A101825,000
V0072/18/2025C003A202350,000
V0083/27/2025C002A1021510,000
V0095/6/2025C004A201625,000
V0107/14/2025C005A202350,000
V0119/30/2025C007A202250,000
V01212/2/2025C006A102510,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:

Revenue = SUM( Sales[Amount] )
Power BI accepts this DAX foryes, Measureyes, Calculated columnno, Calculated tableno, Virtual table

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:

The visual by city, and the visible sales
CityRevenue
900,000
500,000
300,000
1,700,000
Sale IDCustomer cityCategoryAmount
V001New YorkSedan250,000
V002New YorkSUV150,000
V003ChicagoSedan100,000
V004ChicagoCity car100,000
V005TorontoSedan150,000
V006New YorkSedan200,000
V007New YorkSUV150,000
V008New YorkCity car150,000
V009ChicagoSedan150,000
V010ChicagoSUV150,000
V011TorontoSUV100,000
V012TorontoCity car50,000
SUM( Sales[Amount] ) returns 900,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?

Key takeaways
  • 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.