Table.LastN
The last rows of a table: a number of them, or as many as meet a condition from the bottom up.
Group: Table. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Table.LastN(table as table, countOrCondition as any) as table
| Parameter | Type | Description |
|---|---|---|
table | table | The table to read. |
countOrCondition | any | How many rows to keep, or a condition: rows are kept from the bottom while it holds. |
Returns
table. The rows kept, in the table's order.
Remarks
- With a condition, the first row from the bottom that fails it ends the result.
Examples
The last two lines
Table.LastN(#table({"Product", "Price", "Units"}, {{"Chair", 50, 4}, {"Desk", 120, 1}, {"Lamp", 30, 6}}), 2)
| Product | Price | Units |
|---|---|---|
| Desk | 120 | 1 |
| Lamp | 30 | 6 |
From the bottom while the price is under 100
let
Lines = #table({"Product", "Price"}, {{"Chair", 50}, {"Desk", 120}, {"Lamp", 30}, {"Rug", 80}})
in
Table.LastN(Lines, each [Price] < 100)
| Product | Price |
|---|---|
| Lamp | 30 |
| Rug | 80 |