Table.MaxN
This topic applies to the Power Query Formula Language which can be used with Power Query and Power BI Desktop to build queries that mashup data. See the list of function categories.
Returns the largest N rows from a table. After the rows are sorted, the countOrCondition parameter must be specified to further filter the result.
Table.MaxN(table as table, comparisonCriteria as any, countOrCondition as any) as table
| Argument | Description |
|---|---|
| table | The Table to check. |
| comparisonCriteria | Largest N rows comparison criteria. |
| countOrCondition | After the rows are sorted, countOrCondition further filters the result. |
The countOrCondition arument has two possible settings:
| Argument | Description |
|---|---|
| as a number | A list of items up to countOrCondition items in ascending order is returned. |
| as a condition | A list of items that initially meet the condition is returned. Once an item fails the condition, no further items are considered. |
Table.MaxN(Employees, "Salary", 3)
equals Table.FromRecords({[Name="Jeff", Level=10, Salary=200000]
[Name="Barb", Level=8, Salary=150000]
[Name="Bill", Level=7, Salary=100000]})
Table.MaxN(Employees, "Salary", each [Level] > 7)
equals Table.FromRecords( {[Name="Jeff", Level=10, Salary=200000]
[Name="Barb", Level=8, Salary=150000]})
Show: