09.4A measure has no row context
A calculated column knows which row it is on. A measure does not. This difference explains an error that many beginners run into, and this lesson shows how to fix it. If a formula accepted in a calculated column is rejected in a measure, you did not mistype anything, this difference is at play.
09.4.1A bare column in a measure
Let’s try to write the amount as a measure, with the same formula as the Amount column:
Power BI rejects this measure.
Why? In the calculated column, Sales[Qty] returned the quantity of each row. A measure, on the other hand, is calculated on the visible rows, with no current row.
On the “Total” row of a visual, the 12 sales are visible. Sales[Qty] therefore has 12 values:
| V001 | V002 | V003 | V004 | V005 | V006 | V007 | V008 | V009 | V010 | V011 | V012 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 10 | 3 | 4 | 10 | 6 | 8 | 3 | 15 | 6 | 3 | 2 | 5 |
Which one should it take? DAX cannot guess. So Power BI rejects the formula as soon as you write it, even if only one sale were visible, because a measure has no current row. If one of your measures is rejected for this reason, the Diagnostic guides you step by step.
09.4.2Reducing the column to a single value
In a measure, a column must therefore go through a function that reduces its values to a single one, an aggregator like SUM:
SUM adds up the 12 quantities and returns a single value, 75. The measure is accepted.
To carry out a calculation row by row in a measure, like the quantity times the price, use an iterator, like SUMX. It places itself on each row, and so creates a row context. Another lesson shows this later.
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
Which of these measures does Power BI accept?
Question 2
Which of these measures does Power BI reject?
Question 3
A visual has one row per “Sale ID.” Each row therefore leaves only one sale visible. Does the measure Sales[Qty] * Sales[Price] work there?
- A measure is calculated on the visible rows, with no current row.
- In a measure, a bare column is rejected. It goes through a function like SUM, which returns a single value.
- To calculate row by row in a measure, use an iterator, which creates a row context.