PREVIOUS
In a visual calculation, a column's value at the previous row along an axis, or a number of rows back.
A visual calculation works on the table behind a visual: a row for each group on the visual's axes and one for each of their totals. To try one in the OAX view, give a table that shape with DEFINE TABLE ... WITH VISUAL SHAPE: its axes, their groups, the TRUE/FALSE column that marks each group's totals and the order, and with DENSIFY a name for the column that marks rows the shape fills in. Then write the calculation as a COLUMN of that table, as Power BI's own queries do. The examples below are queries of that kind, small enough to check by hand.
Group: Window and visual calculations. Compatible with DAX.
Syntax
PREVIOUS ( <column> [, <steps>] [, <axis>] [, <orderBy>] [, <blanks>] [, <reset>] )
| Parameter | Type | Description |
|---|---|---|
column | Column | A field of the visual, such as [Liters]. An expression is not allowed here: make it a visual calculation of its own and name that. |
steps | Whole number optional | How many rows back; 1 when left out. It must be 1 or more. |
axis | Axis optional | Which way to go: ROWS or COLUMNS, or both, as ROWS COLUMNS, which goes down the rows first and then across the columns; ROWPAGES for small multiples. Left out, the visual's first axis. |
orderBy | ORDERBY optional | ORDERBY ( ... ) to take the rows in another order than the axis has. |
blanks | Keyword optional | With an ORDERBY: where blank values go, DEFAULT, FIRST or LAST. |
reset | Reset optional | Where it starts again: NONE (when left out) never; HIGHESTPARENT (or 1, or the axis's top column) at each value of the top group; LOWESTPARENT (or -1) at each row's own parent; another whole number, or a column of the axis, at that level. |
Returns
Same type as the column. The column's value that many rows before the current one.
Remarks
- On the first rows, where there is nothing that far back, the result is BLANK; so it is just after a reset.
[Liters] - PREVIOUS ( [Liters] )is the change from the row before.- Each level of the visual is walked on its own: the quarters' rows among the quarters, the years' subtotals among the years, the grand total by itself. Without a reset, the first quarter of 2026 looks back to the last quarter of 2025.
- With years on the columns,
PREVIOUS ( [Liters], COLUMNS )is the same row's year before. - It is the visual calculation's counterpart of
OFFSET ( -1 )along an axis. - It works only in a visual calculation; in a measure, a calculated column or a plain query it is an error.
Examples
Change from the month before
DEFINE
TABLE Visual =
DATATABLE (
"Month", INTEGER, "Liters", INTEGER,
{ { 1, 100 }, { 2, 150 }, { 3, 120 }, { 4, 90 } }
)
WITH VISUAL SHAPE
AXIS ROWS GROUP [Month] ORDER BY [Month]
DENSIFY "Added"
COLUMN Visual[Previous] = PREVIOUS ( [Liters] )
COLUMN Visual[Two back] = PREVIOUS ( [Liters], 2 )
COLUMN Visual[Change] = [Liters] - PREVIOUS ( [Liters] )
EVALUATE
SELECTCOLUMNS (
Visual,
"Month", [Month], "Liters", [Liters],
"Previous", [Previous],
"Two back", [Two back],
"Change", [Change]
)
ORDER BY [Month]
| Month | Liters | Previous | Two back | Change |
|---|---|---|---|---|
| 1 | 100 | (blank) | (blank) | 100 |
| 2 | 150 | 100 | (blank) | 50 |
| 3 | 120 | 150 | 100 | -30 |
| 4 | 90 | 120 | 150 | -30 |
Along the columns
Products on the rows, years on the columns: each product's year before.
DEFINE
TABLE Visual =
DATATABLE (
"Product", STRING, "Year", INTEGER, "Liters", INTEGER, "All products", BOOLEAN, "All years", BOOLEAN,
{
{ "IPA", 2025, 60, FALSE, FALSE }, { "IPA", 2026, 80, FALSE, FALSE }, { "IPA", BLANK (), 140, FALSE, TRUE },
{ "Pils", 2025, 100, FALSE, FALSE }, { "Pils", 2026, 120, FALSE, FALSE }, { "Pils", BLANK (), 220, FALSE, TRUE },
{ BLANK (), 2025, 160, TRUE, FALSE }, { BLANK (), 2026, 200, TRUE, FALSE }, { BLANK (), BLANK (), 360, TRUE, TRUE }
}
)
WITH VISUAL SHAPE
AXIS ROWS GROUP [Product] TOTAL [All products] ORDER BY [Product]
AXIS COLUMNS GROUP [Year] TOTAL [All years] ORDER BY [Year]
DENSIFY "Added"
COLUMN Visual[Year before] = PREVIOUS ( [Liters], COLUMNS )
EVALUATE
SELECTCOLUMNS (
Visual,
"Product", [Product], "Year", [Year], "Liters", [Liters],
"Year before", [Year before]
)
ORDER BY ISBLANK ( [Product] ), [Product], ISBLANK ( [Year] ), [Year]
| Product | Year | Liters | Year before |
|---|---|---|---|
| IPA | 2025 | 60 | (blank) |
| IPA | 2026 | 80 | 60 |
| IPA | (blank) | 140 | (blank) |
| Pils | 2025 | 100 | (blank) |
| Pils | 2026 | 120 | 100 |
| Pils | (blank) | 220 | (blank) |
| (blank) | 2025 | 160 | (blank) |
| (blank) | 2026 | 200 | 160 |
| (blank) | (blank) | 360 | (blank) |
Not across the years
DEFINE
TABLE Visual =
DATATABLE (
"Year", INTEGER, "Quarter", INTEGER, "Liters", INTEGER, "All years", BOOLEAN, "All quarters", BOOLEAN,
{
{ 2025, 1, 100, FALSE, FALSE }, { 2025, 2, 120, FALSE, FALSE }, { 2025, BLANK (), 220, FALSE, TRUE },
{ 2026, 1, 130, FALSE, FALSE }, { 2026, 2, 150, FALSE, FALSE }, { 2026, BLANK (), 280, FALSE, TRUE },
{ BLANK (), BLANK (), 500, TRUE, TRUE }
}
)
WITH VISUAL SHAPE
AXIS ROWS
GROUP [Year] TOTAL [All years]
GROUP [Quarter] TOTAL [All quarters]
ORDER BY [Year], [Quarter]
DENSIFY "Added"
COLUMN Visual[Previous] = PREVIOUS ( [Liters] )
COLUMN Visual[In the same year] = PREVIOUS ( [Liters], HIGHESTPARENT )
EVALUATE
SELECTCOLUMNS (
Visual,
"Year", [Year], "Quarter", [Quarter], "Liters", [Liters],
"Previous", [Previous],
"In the same year", [In the same year]
)
ORDER BY ISBLANK ( [Year] ), [Year], ISBLANK ( [Quarter] ), [Quarter]
| Year | Quarter | Liters | Previous | In the same year |
|---|---|---|---|---|
| 2025 | 1 | 100 | (blank) | (blank) |
| 2025 | 2 | 120 | 100 | 100 |
| 2025 | (blank) | 220 | (blank) | (blank) |
| 2026 | 1 | 130 | 120 | (blank) |
| 2026 | 2 | 150 | 130 | 130 |
| 2026 | (blank) | 280 | 220 | (blank) |
| (blank) | (blank) | 500 | (blank) | (blank) |
Related functions
NEXT, FIRST, OFFSET, RUNNINGSUM.