List.RemoveLastN
A list without its last items: 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.RemoveLastN(list as list, optional countOrCondition as any) as list
| Parameter | Type | Description |
|---|---|---|
list | list | The list. |
countOrCondition | any optional | A number of items to remove (1 when left out), or a function of one item: items are removed from the end while it answers true. |
Returns
list. The list up to the removed items.
Examples
Without the total at the end
List.RemoveLastN({"Coffee", "Tea", "Total"})
{"Coffee", "Tea"}
Trailing empty readings removed
List.RemoveLastN({10, 20, null, null}, each _ = null)
{10, 20}