List.MaxN
ListReturns the N largest values from a list, or values meeting a condition, in descending order.
Syntax
List.MaxN(list as list, countOrCondition as any, optional comparisonCriteria as any) as listParameters
| Name | Type | Required | Description |
|---|---|---|---|
list | list | Yes | The list to search. |
countOrCondition | any | Yes | A number specifying how many maximum values to return, or a condition function. |
comparisonCriteria | any | No | An optional comparison criteria or comparer function to control ordering. |
Return Value
list — A 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 2: Return top values while they exceed a threshold
List.MaxN({50, 40, 30, 20, 10}, each _ >= 30)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
TopThreeThe final output — returns the 3 largest sales amounts from the list, sorted in descending order.
Result | |
|---|---|
| 1 | 3,400 |
| 2 | 2,100 |
| 3 | 1,200 |