Table.LastN
This function retrieves the final row(s) from the specified table, based on the input value of countOrCondition: - If countOrCondition is a numerical value, then that number of rows will be fetched s...
This function retrieves the final row(s) from the specified table, based on the input value of countOrCondition:
- If countOrCondition is a numerical value, then that number of rows will be fetched starting from the position (end - countOrCondition).
- If countOrCondition is a conditional statement, the function will return rows that satisfy the condition in ascending order until a row no longer meets the condition.
Get the final two rows of the given table using Power Query M.
```
Table.LastN(
Table.FromRecords({
[CustomerID = 1, Name = "Bob", Phone = "123-4567"],
[CustomerID = 2, Name = "Jim", Phone = "987-6543"],
[CustomerID = 3, Name = "Paul", Phone = "543-7890"]
}),
2)
```
Result:
```
Table.FromRecords({
[CustomerID = 2, Name = "Jim", Phone = "987-6543"],
[CustomerID = 3, Name = "Paul", Phone = "543-7890"]
})
```
Identify the last rows in the table where the value of column [a] is greater than 0 using Power Query M.
```
Table.LastN(
Table.FromRecords({
[a = -1, b = -2],
[a = 3, b = 4],
[a = 5, b = 6]
}),
each _ [a] > 0)
```
Result:
```
Table.FromRecords({
[a = 3, b = 4],
[a = 5, b = 6]
})
```