argmax
argmax, aggregator
def process argmax(key: number, value: any): any
Returns the item of value corresponding to the maximum value of key. If multiple rows have the same maximum key value, one is chosen arbitrarily.
key: The number used for ordering.value: The paired value returned from the corresponding row.
Examples
Basic usage
table T = with
[| as Product, as Price, as Weight |]
[| "Widget A", 100, 2.5 |]
[| "Widget B", 150, 1.8 |]
[| "Widget C", 75, 3.2 |]
mostExpensiveProduct = argmax(T.Price, T.Product)
heaviestProduct = argmax(T.Weight, T.Product)
show summary "Product Analysis" with
mostExpensiveProduct as "Most Expensive Product"
heaviestProduct as "Heaviest Product"
This produces:
| Most Expensive Product | Heaviest Product |
|---|---|
| Widget B | Widget C |
Remarks
When multiple rows share the same T.A value, argmax chooses the corresponding T.B value arbitrarily. Since argmax works as a sequential scan over the table, reordering the rows may lead to different outputs in cases of ties.