List.First
Returns the first item in a list.
List.First(list, optional default)Returns: The first item, or the default when the list is empty.
What it does
List.First returns the item at the start of a list. Use it when the list is already in the order you want, for example the first transaction after a sort, or the opening balance from a list of month-end figures. If the list is empty, it returns the default you give, or null.
Syntax and arguments
list: the list to read.default(optional): the value returned when the list has no items.
Example
A fixed-asset register lists the depreciation for each period, starting with the first period. The reviewer needs the first value, and a message if the list is empty.
let
DepreciationByPeriod = {1250, 1250, 1250},
FirstCharge = List.First(DepreciationByPeriod, 0),
NoCharge = List.First({}, "no periods")
in
FirstCharge
FirstCharge is 1250. The second line shows the default at work: an empty list gives the text "no periods" instead of a null that could break a later step.
Example: a second, different use
Taking the earliest date after a sort: List.First(List.Sort(PaymentDates)) returns the first payment date in ascending order.
Things to watch
- List.First does not sort. Take the first item of the sorted list, not the first item of the original, unless the original order is what you need.
- Use a default when the list may be empty. Otherwise an empty list produces null.
- To read the first row of a table, use Table.First, which returns a record.
- For the first few items, use List.FirstN.
In business terms
Opening balances, first period charges, earliest transactions in a period and the first approver in a list are typical uses. State the order of the list in the notes, because "first" depends on the sort.