Table.LastN
TableReturns the last N rows from a table, or rows matching a condition from the end.
Syntax
Table.LastN(table as table, countOrCondition as any) as tableParameters
| Name | Type | Required | Description |
|---|---|---|---|
table | table | Yes | The table to take rows from. |
countOrCondition | any | Yes | A number specifying how many rows to return, or a function that returns rows from the end while the condition is true. |
Return Value
table — A table containing the last N rows, or the last rows that satisfy the condition.
Remarks
Table.LastN returns rows from the end of a table. When passed a number, it returns that many rows from the bottom. When passed a condition function, it scans backward from the last row and returns consecutive rows while the condition is true.
This is the complement of Table.FirstN. Use Table.LastN to get the most recent rows from a date-sorted table, or to grab a trailing set of records.
Examples
Example 1: Get last 2 rows
Table.SelectColumns(Table.LastN(Sales, 2), {"OrderID", "CustomerName", "Product", "Region"})Result
OrderID | CustomerName | Product | Region | |
|---|---|---|---|---|
| 1 | 7 | Charlie | Widget C | West |
| 2 | 8 | Diana | Gadget B | North |
Compatibility
✓ Power BI Desktop✓ Power BI Service✓ Excel Desktop✓ Excel Online✓ Dataflows✓ Fabric Notebooks