argmin

argmin, function

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

Returns the value associated with the minimum key. If multiple rows share the minimum 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
  argmin(T.Price, T.Product) as "Cheapest"
  argmin(T.Weight, T.Product) as "Lightest"

Output:

Cheapest Lightest
Widget C Widget B

Remarks

When multiple rows share the same minimum 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