Table.MaxN

This function retrieves the row(s) with the highest value in the table based on the comparisonCriteria provided. The rows will be sorted before the result is further filtered using the countOrConditio...

Syntax

Table.MaxN(table as table, comparisonCriteria as any, countOrCondition as any) as table

About

This function retrieves the row(s) with the highest value in the table based on the comparisonCriteria provided. The rows will be sorted before the result is further filtered using the countOrCondition parameter. It is important to note that the sorting algorithm does not guarantee a specific sorted outcome. The countOrCondition parameter can be specified in two ways: 1. If a number is provided, up to that number of items will be returned in ascending order. 2. If a condition is specified, only items that initially meet the condition will be returned. Once an item no longer fulfills the condition, the search will stop.

Explanation

Identify the row in the table where the value in column [a] is the highest while meeting the condition [a] > 0. The rows are organized before applying the filter. Usage: Power Query M Table.MaxN( Table.FromRecords({ [a = 2, b = 4], [a = 0, b = 0], [a = 6, b = 2] }), "a", each [a] > 0) Output: Table.FromRecords({ [a = 6, b = 2], [a = 2, b = 4] }) Identify the row in the table where the value in column [a] is the highest while meeting the condition [b] > 0. The rows are sorted before applying the filter. Usage: Power Query M Table.MaxN( Table.FromRecords({ [a = 2, b = 4], [a = 8, b = 0], [a = 6, b = 2] }), "a", each [b] > 0) Output: Table.FromRecords({})