Table.RemoveFirstN

Table

Removes the first N rows of a table, or rows while a condition is true.

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

Syntax

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

Parameters

NameTypeRequiredDescription
tabletableYesThe table to remove rows from.
countOrConditionanyYesA number specifying how many rows to remove, or a condition function that removes rows while it returns true.

Return Value

tableThe 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)
Result
OrderID
CustomerName
Product
Region
13CharlieWidget CEast
24DianaWidget ANorth

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)
Result
OrderID
CustomerName
OrderDate
13Charlie2024-02-01
28Diana2024-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], "#"))
Result
Content
1OrderID,Customer,Amount
21,Alice,100
32,Bob,200

Compatibility

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