Table.LastN

Table

Returns the last N rows from a table, or rows matching a condition from the end.

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

Syntax

Table.LastN(table as table, countOrCondition as any) as table

Parameters

NameTypeRequiredDescription
tabletableYesThe table to take rows from.
countOrConditionanyYesA number specifying how many rows to return, or a function that returns rows from the end while the condition is true.

Return Value

tableA 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
17CharlieWidget CWest
28DianaGadget BNorth

Compatibility

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