LAST DAX Function (Visual calculations)

The Last function retrieves a value in the Visual Calculation data grid from the last row of an axis.

Syntax

LAST ( <Column> [, <Axis>] [, <OrderBy>] [, <Blanks>] [, <Reset>] )
Parameter Attributes Description
Column

The column from which to retrieve the value.

Axis Optional

An axis reference.

OrderBy Optional

Columns that define how each partition is sorted.

Blanks Optional

Defines how to handle BLANK OrderBy values. Valid values include: DEFAULT, FIRST, LAST.

Reset Optional

Specifies how the calculation restarts. Valid values are: None, LowestParent, HighestParent, or an integer.

Return values

Scalar A single value of any type.

The value of Column in the last row of the axis, at the level of the current row. With Reset, the last row of the current partition.

Notes

The visual calculation functions have an axis parameter that is defined in the VISUAL SHAPE query syntax produced by the visual calculation feature in Power BI.

Remarks

LAST can be used only in a visual calculation. In a measure or in a calculated column, LAST returns an error.

Column must be a column of the visual calculation data grid, such as a field of the visual or another visual calculation. An expression, such as [Sales Amount] * 2, returns an error. To use an expression, define it first in another visual calculation.

LAST works on each level of the axis separately. For example, with Year and Quarter on rows, LAST returns the value of the last quarter in a quarter row, the value of the last year in a year row, and the value of the total in the total row.

If you omit Axis, LAST uses the first axis of the visual shape. If the visual does not have the axis, for example COLUMNS in a visual with only rows, LAST returns the value of the current row.

Without OrderBy, LAST sorts the rows by the columns of the axis, in ascending order. With OrderBy, LAST sorts the rows by the OrderBy expressions. For example, LAST ( [Quarter], ROWS, ORDERBY ( [Sales Amount], DESC ) ) returns the quarter with the smallest Sales Amount. Blanks defines the position of BLANK values in this sort order. With DEFAULT, a BLANK number is between zero and the negative numbers, and a BLANK text is before all the other texts. With the value FIRST, BLANK values are always at the start. With the value LAST, BLANK values are always at the end. This is true for ascending and descending order.

Reset restarts the calculation at a level of the axis. NONE or 0 is the default: the calculation does not restart. HIGHESTPARENT or 1 restarts on each value of the highest level. LOWESTPARENT or -1 restarts on each value of the parent of the current level. A positive integer counts the levels from the highest level, and a negative integer counts the levels up from the current level. A column reference restarts on each value of that column. If the reset level is absolute (HIGHESTPARENT, a positive integer, or a column reference) and the current row is at that level or above, the partition has only the current row. In this case, LAST returns the value of the current row. For example, with HIGHESTPARENT, a year row returns the value of that year.

You cannot use Reset together with OrderBy. LAST returns an error.

To get the value of the first row, use FIRST. To get the value of the previous or next row, use PREVIOUS or NEXT.

» 1 related article
» 3 related functions

Examples

--  LAST returns a value from the last row of the ROWS axis.
--  The query simulates a matrix with Year and Quarter on rows.
--  Last:         last row of the same level (last year, last quarter)
--  LastInYear:   HIGHESTPARENT restarts on each year;
--                a year row returns its own value
--  VsLast:       difference from LastInYear
--  WorstQuarter: ORDERBY sorts the rows by Sales Amount, descending
DEFINE
    COLUMN '__V'[Last] = LAST ( [Sales Amount], ROWS )
    COLUMN '__V'[LastInYear] = LAST ( [Sales Amount], ROWS, HIGHESTPARENT )
    COLUMN '__V'[VsLast] = [Sales Amount] - LAST ( [Sales Amount], ROWS, HIGHESTPARENT )
    COLUMN '__V'[WorstQuarter] = LAST ( [Quarter], ROWS, ORDERBY ( [Sales Amount], DESC ) )
    VAR __Core =
        SUMMARIZECOLUMNS (
            ROLLUPADDISSUBTOTAL (
                'Date'[Calendar Year Number], "IsGrandTotalRowTotal",
                'Date'[Calendar Year Quarter Number], "IsYearTotal"
            ),
            TREATAS ( { 2007, 2008 }, 'Date'[Calendar Year Number] ),
            "Sales_Amount", [Sales Amount]
        )
    VAR __Input =
        SELECTCOLUMNS (
            __Core,
            "Year", 'Date'[Calendar Year Number],
            "Quarter", 'Date'[Calendar Year Quarter Number],
            "IsGrandTotalRowTotal", [IsGrandTotalRowTotal],
            "IsYearTotal", [IsYearTotal],
            "Sales Amount", [Sales_Amount]
        )
    TABLE '__V' = __Input
        WITH VISUAL SHAPE
        AXIS ROWS
            GROUP [Year] TOTAL [IsGrandTotalRowTotal]
            GROUP [Quarter] TOTAL [IsYearTotal]
            ORDER BY [Year] ASC, [Quarter] ASC
        DENSIFY "IsDensifiedRow"
EVALUATE
SELECTCOLUMNS (
    '__V',
    "Year", [Year],
    "Quarter", [Quarter],
    "Sales Amount", [Sales Amount],
    "Last", [Last],
    "LastInYear", [LastInYear],
    "VsLast", [VsLast],
    "WorstQuarter", [WorstQuarter]
)
ORDER BY [Year], [Quarter]
Year Quarter Sales Amount Last LastInYear VsLast WorstQuarter
(Blank) (Blank) 21,237,529.11 21,237,529.11 21,237,529.11 0.00 (Blank)
2007 (Blank) 11,309,946.12 9,927,582.99 11,309,946.12 0.00 (Blank)
2007 20071 2,646,673.39 2,797,611.46 2,731,424.16 -84,750.77 20081
2007 20072 3,046,602.02 2,797,611.46 2,731,424.16 315,177.86 20081
2007 20073 2,885,246.55 2,797,611.46 2,731,424.16 153,822.39 20081
2007 20074 2,731,424.16 2,797,611.46 2,731,424.16 0.00 20081
2008 (Blank) 9,927,582.99 9,927,582.99 9,927,582.99 0.00 (Blank)
2008 20081 1,816,385.21 2,797,611.46 2,797,611.46 -981,226.25 20081
2008 20082 2,738,040.73 2,797,611.46 2,797,611.46 -59,570.73 20081
2008 20083 2,575,545.59 2,797,611.46 2,797,611.46 -222,065.87 20081
2008 20084 2,797,611.46 2,797,611.46 2,797,611.46 0.00 20081

Related articles

Learn more about LAST in the following articles:

Related functions

Other related functions are:

Last update: Nov 20, 2026   » Contribute   » Show contributors

Contributors: Alberto Ferrari, Marco Russo

Microsoft documentation: https://learn.microsoft.com/en-us/dax/last-function-dax

2018-2026 © SQLBI. All rights are reserved. Information coming from Microsoft documentation is property of Microsoft Corp. » Contact us   » Privacy Policy & Cookies

Context Transition

This function performs a Context Transition if called in a Row Context. Click to read more.

Row Context

This expression is executed in a Row Context. Click to read more.

Passed by Expression

This parameter is passed by expression and can be evaluated multiple times in different evaluation contexts.

Iterator

Not recommended

The use of this function is not recommended. See Remarks and Related functions for alternatives.

Not recommended

The use of this parameter is not recommended.

Deprecated

This function is deprecated. Jump to the Alternatives section to see the function to use.

Volatile

A volatile function may return a different result every time you call it, even if you provide the same arguments. Click to read more.

Deprecated

This parameter is deprecated and its use is not recommended.

DirectQuery compatibility

Limitations are placed on DAX expressions allowed in measures and calculated columns.
The state below shows the DirectQuery compatibility of the DAX function.

Contribute

Want to improve the content of LAST? Did you find any issue?
Please, report it us! All submissions will be evaluated for possible updates of the content.