Table.RemoveFirstN
TableRemoves the first N rows of a table, or rows while a condition is true.
Syntax
Table.RemoveFirstN(table as table, countOrCondition as any) as tableParameters
| Name | Type | Required | Description |
|---|---|---|---|
table | table | Yes | The table to remove rows from. |
countOrCondition | any | Yes | A number specifying how many rows to remove, or a condition function that removes rows while it returns true. |
Return Value
table — The table with the first N rows (or leading conditional rows) removed.
Remarks
Table.RemoveFirstN removes rows from the top of the table. When countOrCondition is a number, it removes exactly that many leading rows. When it is a function (predicate), it removes rows from the top while the condition returns true — stopping as soon as the first row that fails the condition is reached, and retaining all rows from that point forward.
This function is equivalent to Table.Skip when given a number. The condition-based form is particularly useful for stripping leading metadata rows from flat files — for example, removing header comment lines that appear before the actual data header, where the number of such lines may vary.
Table.RemoveFirstN does not fold to data sources. For large tables, it materializes the leading rows locally to evaluate the condition. If the leading rows to remove are identifiable at query design time, prefer Table.Skip(n) for slightly clearer intent.
Examples
Example 1: Remove the first 2 orders from the Sales table
let
Sales = #table(
{"OrderID", "CustomerName", "Product", "Region"},
{{1,"Alice","Widget A","East"},{2,"Bob","Gadget B","West"},
{3,"Charlie","Widget C","East"},{4,"Diana","Widget A","North"}}
)
in
Table.RemoveFirstN(Sales, 2)OrderID | CustomerName | Product | Region | |
|---|---|---|---|---|
| 1 | 3 | Charlie | Widget C | East |
| 2 | 4 | Diana | Widget A | North |
Example 2: Remove leading rows where the order date is in January
let
Sales = #table(
{"OrderID", "CustomerName", "OrderDate"},
{{1,"Alice",#date(2024,1,15)},{2,"Bob",#date(2024,1,18)},{3,"Charlie",#date(2024,2,1)},{8,"Diana",#date(2024,4,15)}}
)
in
Table.RemoveFirstN(Sales, each Date.Month([OrderDate]) = 1)OrderID | CustomerName | OrderDate | |
|---|---|---|---|
| 1 | 3 | Charlie | 2024-02-01 |
| 2 | 8 | Diana | 2024-04-15 |
Example 3: Strip leading comment rows from a flat-file import
let
Raw = #table(
{"Content"},
{{"# Generated: 2024-01-01"},{"# Version: 2.0"},{"OrderID,Customer,Amount"},{"1,Alice,100"},{"2,Bob,200"}}
)
in
Table.RemoveFirstN(Raw, each Text.StartsWith([Content], "#"))Content | |
|---|---|
| 1 | OrderID,Customer,Amount |
| 2 | 1,Alice,100 |
| 3 | 2,Bob,200 |