List.FirstN
The first items of a list: a set number of them, or as long as a condition holds.
Group: List. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
List.FirstN(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 while it answers true. |
Returns
any. A list of the items taken from the start, in their order.
Remarks
- A count larger than the list gives the whole list.
- With a condition, taking stops at the first item that fails it, even when later items would pass.
Examples
The first three
List.FirstN({120, 95, 80, 40, 130}, 3)
{120, 95, 80}
While the value is over 50
List.FirstN({120, 95, 80, 40, 130}, each _ > 50)
{120, 95, 80}
130 is over 50 too, but 40 stopped the run before it.