Downloads
Power Query MList: pick and buildBeginner

List.Last

Returns the last item in a list.

Syntax
List.Last(list, optional default)

Returns: The last item, or the default when the list is empty.

What it does

List.Last returns the item at the end of a list. Use it for the closing balance of a month, the most recent payment date after a sort, or the final value of a running total. It is the counterpart of List.First.

Syntax and arguments

Example

A cash ledger lists the balance after each day of the month, in date order. The treasurer needs the closing balance for the month-end pack.

let
    DailyBalances = {15200, 14850, 16100, 15940},
    ClosingBalance = List.Last(DailyBalances, 0)
in
    ClosingBalance

ClosingBalance is 15940, the last value in the list. The default protects the result if a month has no days loaded.

Example: a second, different use

Finding the most recent payment: sort the payment dates in ascending order, then take List.Last to get the latest date.

Things to watch

In business terms

Closing balances, latest rates, most recent statement dates and final period amounts are common uses. Check that the list really ends at the period you want, because a missing day at the end gives a wrong closing figure without an error.

Related functions

All Power Query M functions · View as Markdown · M basics