Table.RemoveRows

Table

Removes a specified number of rows starting at a given offset.

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

Syntax

Table.RemoveRows(table as table, offset as number, optional count as nullable number) as table

Parameters

NameTypeRequiredDescription
tabletableYesThe table to remove rows from.
offsetnumberYesThe zero-based index of the first row to remove.
countnumberNoThe number of rows to remove. Defaults to 1 if omitted.

Return Value

tableThe table with the specified rows removed.

Remarks

Table.RemoveRows removes a contiguous block of rows starting at a zero-based offset. If count is omitted, exactly one row is removed (the row at offset). If count exceeds the number of rows remaining from offset, all rows from offset to the end are removed.

Table.RemoveRows is a positional operation — you need to know the row index in advance. For removing rows from the start or end of the table by count, Table.RemoveFirstN and Table.RemoveLastN are more expressive. For removing rows that match a condition, use Table.RemoveMatchingRows or Table.SelectRows with a negated predicate. For replacing rows at a position, use Table.ReplaceRows.

Table.RemoveRows does not fold to data sources. Combine it with Table.PositionOf to dynamically locate rows before removing them.

Examples

Example 1: Remove a single row at a known position

let
    Customers = #table(
        {"CustomerID", "Name", "City"},
        {{1,"Alice","New York"},{2,"Bob","Chicago"},{3,"Charlie","Houston"},{4,"Diana","Seattle"}}
    )
in
    Table.RemoveRows(Customers, 1)
Result
CustomerID
Name
City
11AliceNew York
23CharlieHouston
34DianaSeattle

Example 2: Remove a block of rows in the middle

let
    Sales = #table(
        {"OrderID", "CustomerName"},
        {{1,"Alice"},{2,"Bob"},{3,"Charlie"},{4,"Alice"},{5,"Diana"},{6,"Bob"},{7,"Charlie"},{8,"Diana"}}
    )
in
    Table.RemoveRows(Sales, 2, 3)
Result
OrderID
CustomerName
11Alice
22Bob
36Bob
47Charlie
58Diana

Example 3: Dynamically locate a row by content, then remove it

let
    Products = #table(
        {"ProductID","ProductName","Price"},
        {{1,"Widget A",25.00},{2,"Gadget B",50.00},{3,"Widget C",15.00},{4,"Gadget D",75.00}}
    ),
    Pos    = Table.PositionOf(Products, [ProductID = 3], Occurrence.First, "ProductID"),
    Result = if Pos >= 0 then Table.RemoveRows(Products, Pos) else Products
in
    Result
Result
ProductID
ProductName
Price
11Widget A25
22Gadget B50
34Gadget D75

Compatibility

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