Table.FirstValue

Table

Returns the value in the first row and first column of the table, or a default value if the table is empty.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

Table.FirstValue(table as table, optional default as nullable any) as any

Parameters

NameTypeRequiredDescription
tabletableYesThe table to read the first value from.
defaultanyNoOptional value to return if the table is empty. Defaults to null.

Return Value

anyThe scalar value from the first cell of the table, or the default if the table is empty.

Remarks

Table.FirstValue extracts a single scalar value from the first row and first column of a table. It is a convenience shorthand for Table.First(table)[firstColumnName] and is most commonly used to read a single expected result after filtering — such as a configuration parameter from a settings table, a count from a summarized dataset, or a lookup result from a reference table.

When the table is empty, Table.FirstValue returns null by default, or the specified default value if provided. This makes it safer than Table.First(table)[Column] in scenarios where the filter might yield no rows, because chaining field access on null would raise an error.

The function always reads the value from the first column. If you need a value from a specific column that is not first, use Table.First(table)[ColumnName] instead. Alternatively, project the table to only the target column with Table.SelectColumns before calling Table.FirstValue.

Examples

Example 1: Read a configuration value from a parameters table

let
    Parameters = #table(
        {"Name", "Value"},
        {{"StartDate", "2024-01-01"}, {"EndDate", "2024-12-31"}, {"MaxRows", "1000"}}
    ),
    Filtered   = Table.SelectRows(Parameters, each [Name] = "MaxRows"),
    Projected  = Table.SelectColumns(Filtered, {"Value"})
in
    Table.FirstValue(Projected)
Result
Result
11000

Example 2: Return a default when no match is found

let
    Parameters = #table(
        {"Name", "Value"},
        {{"StartDate", "2024-01-01"}}
    ),
    Filtered  = Table.SelectRows(Parameters, each [Name] = "Threshold"),
    Projected = Table.SelectColumns(Filtered, {"Value"})
in
    Table.FirstValue(Projected, "100")
Result
Result
1100

Example 3: Extract the lowest unit price from the Products table

let
    Products = #table(
        type table [ProductID = number, ProductName = text, Price = number, InStock = logical],
        {{1,"Widget A",25.00,true},{2,"Gadget B",50.00,true},{3,"Widget C",15.00,false}}
    ),
    Sorted   = Table.Sort(Products, {{"Price", Order.Ascending}}),
    PriceCol = Table.SelectColumns(Sorted, {"Price"})
in
    Table.FirstValue(PriceCol)
Result
Result
115

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks