List.LastN
The last items of a list: a set number of them, or as long as a condition holds from the end.
Group: List. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
List.LastN(list as list, countOrCondition as any) as any
| Parameter | Type | Description |
|---|---|---|
list | list | The list. |
countOrCondition | any | A number of items, or a function of one item: items are taken from the end while it answers true. |
Returns
any. A list of the items taken from the end, in the list's own order.
Remarks
- The count or condition must be given: Power Query's syntax marks it optional, but leaving it out is an error there as here.
Examples
The last two months
List.LastN({40, 80, 95, 120, 130}, 2)
{120, 130}
While the value is over 90, from the end
List.LastN({40, 80, 95, 120, 130}, each _ > 90)
{95, 120, 130}