OpenBI Docs Buy

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>] )
ParameterTypeDescription
columnColumnA field of the visual, such as [Liters]. An expression is not allowed here: make it a visual calculation of its own and name that.
axisAxis
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.
orderByORDERBY
optional
ORDERBY ( ... ) to take the rows in another order than the axis has.
blanksKeyword
optional
With an ORDERBY: where blank values go, DEFAULT, FIRST or LAST.
resetReset
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]
MonthLitersLastTo the last
110090-10
215090-60
312090-30
490900

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]
ProductYearLitersLast year
IPA20256080
IPA20268080
IPA(blank)140140
Pils2025100120
Pils2026120120
Pils(blank)220220
(blank)2025160200
(blank)2026200200
(blank)(blank)360360

FIRST, NEXT, INDEX.

Last updated · OpenBI Studio 0.3.74