Table.FirstN
TableReturns the first N rows from a table, or rows matching a condition.
Syntax
Table.FirstN(table as table, countOrCondition as any) as tableParameters
| Name | Type | Required | Description |
|---|---|---|---|
table | table | Yes | The table to take rows from. |
countOrCondition | any | Yes | A number specifying how many rows to return, or a function (each ...) that returns rows while the condition is true. |
Return Value
table — A 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 | |
|---|---|---|---|---|
| 1 | 1 | Alice | Widget A | East |
| 2 | 2 | Bob | Gadget B | West |
| 3 | 3 | Charlie | Widget C | East |
Example 2: Take rows while condition is true
Table.SelectColumns(Table.FirstN(Sales, each [UnitPrice] < 100), {"OrderID", "Product", "UnitPrice"})Result
OrderID | Product | UnitPrice | |
|---|---|---|---|
| 1 | 1 | Widget A | 25 |
| 2 | 2 | Gadget B | 50 |
| 3 | 3 | Widget C | 15 |
| 4 | 4 | Gadget D | 75 |
| 5 | 5 | Widget A | 25 |
Compatibility
✓ Power BI Desktop✓ Power BI Service✓ Excel Desktop✓ Excel Online✓ Dataflows✓ Fabric Notebooks