Table.RemoveLastN
Drops rows from the bottom: a number of them, or as long as a condition holds.
Group: Table. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Table.RemoveLastN(table as table, optional countOrCondition as any) as table
| Parameter | Type | Description |
|---|---|---|
table | table | The table to drop rows from. |
countOrCondition | any optional | How many rows to drop (1 when left out), or a condition: rows are dropped from the end while it holds. |
Returns
table. The rows that are left, in their order.
Remarks
- With a condition, dropping stops at the last row that fails it, going upwards.
Examples
Without the total line
Table.RemoveLastN(#table({"Product", "Sales"}, {{"Chair", 120}, {"Desk", 340}, {"Total", 460}}))
| Product | Sales |
|---|---|
| Chair | 120 |
| Desk | 340 |
Blank rows at the bottom
let
Raw = #table({"Product", "Sales"}, {{"Chair", 120}, {"Desk", 340}, {null, null}, {null, null}})
in
Table.RemoveLastN(Raw, each [Product] = null)
| Product | Sales |
|---|---|
| Chair | 120 |
| Desk | 340 |