Table.RemoveRows
TableRemoves a specified number of rows starting at a given offset.
Syntax
Table.RemoveRows(table as table, offset as number, optional count as nullable number) as tableParameters
| Name | Type | Required | Description |
|---|---|---|---|
table | table | Yes | The table to remove rows from. |
offset | number | Yes | The zero-based index of the first row to remove. |
count | number | No | The number of rows to remove. Defaults to 1 if omitted. |
Return Value
table — The 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)CustomerID | Name | City | |
|---|---|---|---|
| 1 | 1 | Alice | New York |
| 2 | 3 | Charlie | Houston |
| 3 | 4 | Diana | Seattle |
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)OrderID | CustomerName | |
|---|---|---|
| 1 | 1 | Alice |
| 2 | 2 | Bob |
| 3 | 6 | Bob |
| 4 | 7 | Charlie |
| 5 | 8 | Diana |
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
ResultProductID | ProductName | Price | |
|---|---|---|---|
| 1 | 1 | Widget A | 25 |
| 2 | 2 | Gadget B | 50 |
| 3 | 4 | Gadget D | 75 |