Table.First

Table

Returns the first row of the table as a record, 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.First(table as table, optional default as nullable any) as any

Parameters

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

Return Value

anyThe first row as a record, or the default value if the table is empty.

Remarks

Table.First returns the first row of a table as a record, enabling field access via [FieldName] syntax. If the table is empty and no default value is specified, the function returns null. Providing a default record prevents null propagation errors in downstream steps when the table might occasionally be empty — for example, after a filter that may match zero rows.

Table.First is commonly used after filtering to extract a single expected result (e.g., looking up a configuration value or getting the most recent transaction after sorting). For cases where you need to enforce that exactly one row exists, use Table.SingleRow instead, which will raise an error if the table has zero or more than one row. For reading just the top-left scalar value without unpacking a record, Table.FirstValue is more concise.

After sorting, Table.First efficiently returns the top row without materializing the entire sorted result into memory — the engine can short-circuit the evaluation. However, Table.First alone (without a prior sort) returns whichever row happens to be first in the table's current order, which may not be deterministic for database sources.

Examples

Example 1: Get the earliest order from the Sales table

let
    Sales = #table(
        {"OrderID", "CustomerName", "Product", "UnitPrice", "Quantity", "OrderDate", "Region"},
        {{1,"Alice","Widget A",25.00,4,#date(2024,1,15),"East"},
         {2,"Bob","Gadget B",50.00,2,#date(2024,1,18),"West"},
         {3,"Charlie","Widget C",15.00,10,#date(2024,2,1),"East"}}
    ),
    Sorted = Table.Sort(Sales, {{"OrderDate", Order.Ascending}})
in
    Table.First(Sorted)
Result
Result
1[OrderID = 1, CustomerName = "Alice", Product = "Widget A", UnitPrice = 25, Quantity = 4, OrderDate = #date(2024,1,15), Region = "East"]

Example 2: Extract a specific field from the first row

let
    Sales = #table(
        {"OrderID", "CustomerName", "Product", "UnitPrice"},
        {{1,"Alice","Widget A",25.00},{2,"Bob","Gadget B",50.00}}
    ),
    Sorted = Table.Sort(Sales, {{"UnitPrice", Order.Descending}})
in
    Table.First(Sorted)[Product]
Result
Result
1Gadget B

Example 3: Return a safe default when the filter matches no rows

let
    Sales = #table(
        {"OrderID", "CustomerName", "Region"},
        {{1,"Alice","East"},{2,"Bob","West"}}
    ),
    Filtered = Table.SelectRows(Sales, each [Region] = "North")
in
    Table.First(Filtered, [OrderID = 0, CustomerName = "None", Region = "N/A"])
Result
Result
1[OrderID = 0, CustomerName = "None", Region = "N/A"]

Compatibility

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