OpenBI Docs Buy

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
ParameterTypeDescription
tabletableThe table to read.
countOrConditionanyHow 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)
ProductPriceUnits
Chair504
Desk1201

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)
ProductPrice
Chair50
Lamp30

The desk ends it: the rug, at 80, is not kept.

Table.LastN, Table.First, Table.Skip, Table.SelectRows.

Last updated · OpenBI Studio 0.3.79