argwhichever
argwhichever, aggregator
def nosort process argwhichever() : boolean
def process argwhichever(t: boolean) : boolean
This aggregator returns true for one selected row within each group. In its no-argument version, it arbitrarily selects one row; in the version with a boolean condition provided as t
, it returns true for one row where t
is true.
Examples
Example 1: No-argument version
table Products = with
[| as Label, as UnitPrice |]
[| "Hat", 15.00 |]
[| "Shirt", 15.00 |]
[| "Pants", 25.00 |]
Products.IsTrue = argwhichever() by Products.UnitPrice
show table "" a1c3 with
Products.Label
Products.UnitPrice
Products.IsTrue
One possible outcome is:
Label | UnitPrice | IsTrue |
---|---|---|
Hat | 15.00 | true |
Shirt | 15.00 | false |
Pants | 25.00 | true |
Note: In groups with multiple rows, the row marked true is chosen arbitrarily.
Example 2: With boolean condition
table Products = with
[| as Label, as UnitPrice, as Eligible |]
[| "Hat", 15.00, false |]
[| "Shirt", 15.00, true |]
[| "Pants", 25.00, true |]
Products.IsTrue = argwhichever(Products.Eligible) by Products.UnitPrice
show table "" a1c3 with
Products.Label
Products.UnitPrice
Products.IsTrue
Based on the eligibility condition, the expected outcome is:
Label | UnitPrice | Eligible | IsTrue |
---|---|---|---|
Hat | 15.00 | false | false |
Shirt | 15.00 | true | true |
Pants | 25.00 | true | true |
Note: Only rows meeting the boolean condition are eligible for selection.