Power Query
published
Search
K

List.LastN

List.LastN

Returns the last value in the list. Can optionally specify how many values to return or a qualifying condition.
function (list as list, optional countOrCondition as nullable any) as nullable any

Description

Returns the last item of the list list. If the list is empty, an exception is thrown. This function takes an optional parameter, countOrCondition, to support gathering multiple items or filtering items. countOrCondition can be specified in three ways:

Category

List.Selection

Examples

Find the last value in the list {3, 4, 5, -1, 7, 8, 2}.
List.LastN({3, 4, 5, -1, 7, 8, 2},1)
{2}
Find the last values in the list {3, 4, 5, -1, 7, 8, 2} that are greater than 0.
List.LastN({3, 4, 5, -1, 7, 8, 2}, each _ > 0)
{7, 8, 2}