FIRST DAX Function (Visual calculations)

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

Syntax

FIRST ( <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 first row of the axis, at the level of the current row. With Reset, the first 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

FIRST can be used only in a visual calculation. In a measure or in a calculated column, FIRST 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.

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

If you omit Axis, FIRST 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, FIRST returns the value of the current row.

Without OrderBy, FIRST sorts the rows by the columns of the axis, in ascending order. With OrderBy, FIRST sorts the rows by the OrderBy expressions. For example, FIRST ( [Quarter], ROWS, ORDERBY ( [Sales Amount], DESC ) ) returns the quarter with the largest 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, FIRST 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. FIRST returns an error.

To get the value of the last row, use LAST. To get the value of the previous or next row, use PREVIOUS or NEXT.

» 3 related functions

Examples

--  FIRST returns a value from the first row of the ROWS axis.
--  The query simulates a matrix with Year and Quarter on rows.
--  First:       first row of the same level (first year, first quarter)
--  FirstInYear: HIGHESTPARENT restarts on each year;
--               a year row returns its own value
--  VsFirst:     difference from FirstInYear
--  TopQuarter:  ORDERBY sorts the rows by Sales Amount, descending
DEFINE
    COLUMN '__V'[First] = FIRST ( [Sales Amount], ROWS )
    COLUMN '__V'[FirstInYear] = FIRST ( [Sales Amount], ROWS, HIGHESTPARENT )
    COLUMN '__V'[VsFirst] = [Sales Amount] - FIRST ( [Sales Amount], ROWS, HIGHESTPARENT )
    COLUMN '__V'[TopQuarter] = FIRST ( [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],
    "First", [First],
    "FirstInYear", [FirstInYear],
    "VsFirst", [VsFirst],
    "TopQuarter", [TopQuarter]
)
ORDER BY [Year], [Quarter]
Year Quarter Sales Amount First FirstInYear VsFirst TopQuarter
(Blank) (Blank) 21,237,529.11 21,237,529.11 21,237,529.11 0.00 (Blank)
2007 (Blank) 11,309,946.12 11,309,946.12 11,309,946.12 0.00 (Blank)
2007 20071 2,646,673.39 2,646,673.39 2,646,673.39 0.00 20072
2007 20072 3,046,602.02 2,646,673.39 2,646,673.39 399,928.63 20072
2007 20073 2,885,246.55 2,646,673.39 2,646,673.39 238,573.16 20072
2007 20074 2,731,424.16 2,646,673.39 2,646,673.39 84,750.77 20072
2008 (Blank) 9,927,582.99 11,309,946.12 9,927,582.99 0.00 (Blank)
2008 20081 1,816,385.21 2,646,673.39 1,816,385.21 0.00 20072
2008 20082 2,738,040.73 2,646,673.39 1,816,385.21 921,655.52 20072
2008 20083 2,575,545.59 2,646,673.39 1,816,385.21 759,160.38 20072
2008 20084 2,797,611.46 2,646,673.39 1,816,385.21 981,226.25 20072

Related functions

Other related functions are:

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

Contributors: Alberto Ferrari, Marco Russo

Microsoft documentation: https://learn.microsoft.com/en-us/dax/first-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 FIRST? Did you find any issue?
Please, report it us! All submissions will be evaluated for possible updates of the content.