case
The case
function evaluates a list of predicates and returns the first result expression whose predicate is satisfied.
If neither of the predicates return true
, the result of the last expression (the else
) is returned. All odd arguments (count starts at 1) must be expressions that evaluate to a boolean
value. All even arguments (the then
s) and the last argument (the else
) must be of the same type.
Syntax
case( Predicate_1, Then_1, Predicate_2, Then_2, Predicate_3, Then_3, Else )
Arguments
- Predicate_i: An expression that evaluates to a
boolean
value. - Then_i: An expression that gets evaluated and its value is returned from the function if Predicate_i is the first predicate that evaluates to
true
. - Else: An expression that gets evaluated and its value is returned from the function if neither of the Predicate_i evaluate to
true
.
Results
The value of the first Then_i whose Predicate_i evaluates to true
, or the value of Else if neither of the predicates is satisfied.
Example
dataset=myDataset
| extend bucket = case(Size <= 3, "Small",
Size <= 10, "Medium",
"Large")