Table.FirstN
The first rows of a table: a number of them, or as many as meet a condition from the top.
Group: Table. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Table.FirstN(table as table, countOrCondition as any) as table
| Parameter | Type | Description |
|---|---|---|
table | table | The table to read. |
countOrCondition | any | How many rows to keep, or a condition: rows are kept from the top while it holds. |
Returns
table. The rows kept, with all of the table's columns.
Remarks
- With a condition, the first row that fails it ends the result, even when rows further down would meet it again. To keep every matching row, use
Table.SelectRows.
Examples
The first two lines
Table.FirstN(#table({"Product", "Price", "Units"}, {{"Chair", 50, 4}, {"Desk", 120, 1}, {"Lamp", 30, 6}}), 2)
| Product | Price | Units |
|---|---|---|
| Chair | 50 | 4 |
| Desk | 120 | 1 |
From the top while the price is under 100
let
Lines = #table({"Product", "Price"}, {{"Chair", 50}, {"Lamp", 30}, {"Desk", 120}, {"Rug", 80}})
in
Table.FirstN(Lines, each [Price] < 100)
| Product | Price |
|---|---|
| Chair | 50 |
| Lamp | 30 |
The desk ends it: the rug, at 80, is not kept.