LAST
In a visual calculation, a column's value at the last row along an axis.
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
LAST ( <column> [, <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. |
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 on the last row along the axis.
Remarks
- 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.
- Along
COLUMNS, it is the last column's value on the same row: with years on the columns, each product's latest year. - It is the visual calculation's counterpart of
INDEX ( -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
Against the last month
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[Last] = LAST ( [Liters] )
COLUMN Visual[To the last] = LAST ( [Liters] ) - [Liters]
EVALUATE
SELECTCOLUMNS (
Visual,
"Month", [Month], "Liters", [Liters],
"Last", [Last],
"To the last", [To the last]
)
ORDER BY [Month]
| Month | Liters | Last | To the last |
|---|---|---|---|
| 1 | 100 | 90 | -10 |
| 2 | 150 | 90 | -60 |
| 3 | 120 | 90 | -30 |
| 4 | 90 | 90 | 0 |
The latest year, along the columns
Products on the rows, years on the columns.
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[Last year] = LAST ( [Liters], COLUMNS )
EVALUATE
SELECTCOLUMNS (
Visual,
"Product", [Product], "Year", [Year], "Liters", [Liters],
"Last year", [Last year]
)
ORDER BY ISBLANK ( [Product] ), [Product], ISBLANK ( [Year] ), [Year]
| Product | Year | Liters | Last year |
|---|---|---|---|
| IPA | 2025 | 60 | 80 |
| IPA | 2026 | 80 | 80 |
| IPA | (blank) | 140 | 140 |
| Pils | 2025 | 100 | 120 |
| Pils | 2026 | 120 | 120 |
| Pils | (blank) | 220 | 220 |
| (blank) | 2025 | 160 | 200 |
| (blank) | 2026 | 200 | 200 |
| (blank) | (blank) | 360 | 360 |