Table.MaxN Function in Power Query
The Table.MaxN function returns the largest N rows from a table. After the rows are sorted, the countOrCondition parameter must be specified to further filter the result.
Syntax
Table.MaxN(table as table, comparisonCriteria as any, countOrCondition as any) as table
Note:
- If a number is specified, a list of up to countOrCondition items in ascending order is returned.
- If a condition is specified, a list of items that initially meet the condition is returned. Once an item fails the condition, no further items are considered.
Example: Find the top 3 records.
Power Query M
let MyTable = Table.FromRecords( { [CustomerID = 1, Name = "Ashish", Marks = 568], [CustomerID = 2, Name = "Katrina", Marks = 855], [CustomerID = 3, Name = "Alia", Marks = 380], [CustomerID = 4, Name = "Vicky", Marks = 458], [CustomerID = 5, Name = "Mohini", Marks = 278], [CustomerID = 6, Name = "Meenakshi", Marks = 289], [CustomerID = 7, Name = "Esha", Marks = 875], [CustomerID = 8, Name = "Anjali", Marks = 380] } ), #"Return Output" = Table.MaxN(MyTable, "Marks", 3) in #"Return Output"
The output of the above code is shown below: