List.Last
ListReturns the last item in a list, or a default value if the list is empty.
Syntax
List.Last(list as list, optional defaultValue as any) as anyParameters
| Name | Type | Required | Description |
|---|---|---|---|
list | list | Yes | The list to get the last item from. |
defaultValue | any | No | The value to return if the list is empty. |
Return Value
any — The 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 | |
|---|---|
| 1 | Widget C |
Compatibility
✓ Power BI Desktop✓ Power BI Service✓ Excel Desktop✓ Excel Online✓ Dataflows✓ Fabric Notebooks