List.Last

List

Returns the last item in a list, or a default value if the list is empty.

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

Syntax

List.Last(list as list, optional defaultValue as any) as any

Parameters

NameTypeRequiredDescription
listlistYesThe list to get the last item from.
defaultValueanyNoThe value to return if the list is empty.

Return Value

anyThe last item in the list.

Remarks

List.Last returns the last item from a list. Like List.First, provide a default value to handle empty lists gracefully.

Examples

Example 1: Get the last product name

let
    LastProduct = List.Last(Table.Column(Sales, "Product"))
in
    #table({"LastProduct"}, {{LastProduct}})
Result
LastProduct
1Widget C

Compatibility

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