whichever
There are other concepts named whichever. See the entire list.
whichever, selector
def process whichever(value: any): any
Returns one value per group. Empty groups return the default value for the data
type (or a custom default).
Example
table T = with
[| as Value, as Group |]
[| "x", "a" |]
[| "x", "a" |]
[| "y", "b" |]
table G[g] = with
[| as g |]
[| "a" |]
[| "b" |]
[| "c" |]
G.Value = whichever(T.Value) by T.Group at G.g default "missing"
show table "Whichever" with
g
G.Value
This outputs the following table:
| g | Value |
|---|---|
| a | x |
| b | y |
| c | missing |
Remarks
The chosen value is not guaranteed to be stable across script changes or engine
versions. whichever cannot be used with sort.
When whichever returns embedding values, an explicit default is required.