List.MaxN

List

Returns the N largest values from a list, or values meeting a condition, in descending order.

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

Syntax

List.MaxN(list as list, countOrCondition as any, optional comparisonCriteria as any) as list

Parameters

NameTypeRequiredDescription
listlistYesThe list to search.
countOrConditionanyYesA number specifying how many maximum values to return, or a condition function.
comparisonCriteriaanyNoAn optional comparison criteria or comparer function to control ordering.

Return Value

listA list of the N largest values, sorted in descending order.

Remarks

List.MaxN returns the top N values from a list as a list sorted in descending order. It is the multi-value counterpart of List.Max, which returns a single scalar.

When passed a number N, it returns the N largest values from the list. If N exceeds the list length, the entire list is returned sorted descending. Null values are ignored. Duplicates are preserved — if the Nth-largest value occurs multiple times, all occurrences may be included (the result can have more than N elements in this case).

When passed a condition function, the list is first sorted descending and the condition is applied to each item in that order; items are collected while the condition returns true. This mode is useful for "give me all values above a threshold" scenarios.

For the single highest value, use List.Max. To get the lowest values instead, use List.MinN. To sort and take from a full list, combining List.Sort and List.FirstN is an equivalent and readable alternative.

Examples

Example 1: Return the 3 largest numbers

List.MaxN({15, 3, 42, 8, 27, 1}, 3)
Result
Result
1{42, 27, 15}

Example 2: Return top values while they exceed a threshold

List.MaxN({50, 40, 30, 20, 10}, each _ >= 30)
Result
Result
1{50, 40, 30}

Example 3: Find the top 3 sales amounts

let
    Sales = {1200, 850, 3400, 450, 2100, 975},
    TopThree = List.MaxN(Sales, 3)
in
    TopThree
Applied Steps

The final output — returns the 3 largest sales amounts from the list, sorted in descending order.

Result
13,400
22,100
31,200

Compatibility

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