argmax

argmax, function

def process argmax(key: number, value: any): any

Returns the value associated with the maximum key. If multiple rows share the maximum key, one is chosen arbitrarily.

Examples

table T = with
  [| as Product, as Price, as Weight |]
  [| "Widget A", 100,    2.5         |]
  [| "Widget B", 150,    1.8         |]
  [| "Widget C", 75,     3.2         |]

show summary "Product analysis" with
  argmax(T.Price, T.Product) as "Most Expensive"
  argmax(T.Weight, T.Product) as "Heaviest"

Output:

Most Expensive Heaviest
Widget B Widget C

Remarks

When multiple rows share the same maximum key, the returned value is arbitrary. Reordering rows can change the result in tie cases.

See also

User Contributed Notes
0 notes + add a note