Table.FirstN

Table

Returns the first N rows from a table, or rows matching a condition.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

Table.FirstN(table as table, countOrCondition as any) as table

Parameters

NameTypeRequiredDescription
tabletableYesThe table to take rows from.
countOrConditionanyYesA number specifying how many rows to return, or a function (each ...) that returns rows while the condition is true.

Return Value

tableA table containing the first N rows, or the first rows that satisfy the condition.

Remarks

Table.FirstN returns rows from the beginning of a table. When passed a number, it returns exactly that many rows. When passed a condition function, it returns consecutive rows from the top while the condition is true — it stops at the first row that fails the condition.

The condition form (each [Column] > 0) is different from Table.SelectRows — it stops scanning as soon as the condition fails, rather than checking every row.

Examples

Example 1: Get first 3 rows

Table.SelectColumns(Table.FirstN(Sales, 3), {"OrderID", "CustomerName", "Product", "Region"})
Result
OrderID
CustomerName
Product
Region
11AliceWidget AEast
22BobGadget BWest
33CharlieWidget CEast

Example 2: Take rows while condition is true

Table.SelectColumns(Table.FirstN(Sales, each [UnitPrice] < 100), {"OrderID", "Product", "UnitPrice"})
Result
OrderID
Product
UnitPrice
11Widget A25
22Gadget B50
33Widget C15
44Gadget D75
55Widget A25

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks