19.3Comparing rows with each other
In classic DAX, comparing a row with the one before, with the first one or with the total most often calls for a filter modifier, such as ALL. A visual calculation does it directly.
19.3.1PREVIOUS
In Excel
| Excel | a reference to the row above |
|---|---|
| Match |
You need it to read the gap between a row and the one before, such as the change in revenue from one year to the next.
PREVIOUS can only be written in a visual calculation. Power BI rejects it in a measure, a calculated column or a calculated table.
PREVIOUS returns the value of the row before.
It expects a field of the visual, written in square brackets, such as [Revenue].
| Year | Difference |
|---|---|
| 2024 | 750,000 |
| 2025 | 200,000 |
| Total | 1,700,000 |
This is a reproduction of the Power BI interface for teaching purposes. It differs from the real interface.
On the 2025 row, the difference is 950,000 minus 750,000, that is 200,000.
On the first row, 2024, there is no row before. PREVIOUS returns a blank value, which behaves like zero, and the difference shows 750,000. To avoid this misleading figure, test the row before with IF and ISBLANK.
Practice
Each exercise is solved with the function you just discovered. Two exercises per function, a direct use and a combined use, from easiest to hardest, on data other than the course data. Pick the right formula out of five.
Direct useVisual calculationDifficulty
A dance school has a Table visual by year with its measure “Students,” which counts the students enrolled. On this visual, write the visual calculation “Change from Previous Year,” the students of the row minus those of the row before. The first row needs no special handling.
The visual Year Students 2025 120 2026 150 Which formula should you write for “Change from Previous Year”?
Combined useVisual calculationDifficulty
A carrier has a Table visual by month with its measure “Parcels,” which adds up the parcels. On this visual, write the visual calculation “Difference,” the parcels of the row minus those of the row before. On the first row, there is no row before, and the difference must stay blank.
The visual Month Parcels January 300 February 260
The rest of this lesson is part of izyDAX Pro
You have just read the first section. The next 2, their animations, the exercises and the summary are waiting for you with izyDAX Pro, in a single payment.