The |
For more information on the IF
function, see IF Function.
Example:
case([ Qty <= 10, 'low_qty', Qty >=100, 'high_qty', 'med_qty']) |
Output: Returns a text string based on the evaluation of the Qty
column:
low_qty
high_qty
med_qty
In the following, If the testX
expression evaluates to true
, then the resultX
value is the output.
case([test1, 'result1',test2, 'result2', testn, 'resultn','result_else']) |
Argument | Required? | Data Type | Description |
---|---|---|---|
test1, test2, testn | Y | expression | Expression that is evaluated. Must resolve to true or false |
result1, result2, result2, result_else | Y | string | Quoted string that is written if the corresponding test expression evaluates to true . |
All of these expressions can be constants (strings, integers, or any other supported literal values) or sophisticated elements of logic, although the test expression must evaluate to a Boolean value.
These parameters contain the expressions to evaluate. This expression must resolve to a Boolean (true
or false
) value.
NOTE: The syntax of a test expression follows the same syntax as the |
Required? | Data Type | Example Value |
---|---|---|
Yes | Expression that evaluates to true or false | (OrderAge > 90) |
If the corresponding test expression evaluates to true
, this value is written as the result.
These expressions can literals of any data type or expressions that evaluate to literals of any data type.
Required? | Data Type | Example Value |
---|---|---|
Yes | Literal value or expression | See examples below. |
The following data represents orders received during the week. Discounts are applied to the orders based on the following rules:
OrdDate | CustId | Qty | Std_Disc |
---|---|---|---|
5/8/17 | C001 | 4 | 0.05 |
5/9/17 | C002 | 11 | 0.05 |
5/10/17 | C003 | 4 | 0.05 |
5/11/17 | C001 | 25 | 0.05 |
5/12/17 | C002 | 19 | 0.05 |
Transforms:
To determine the day of the week, you can use the following transformation:
You can build the discount rules into the following transform, which generates the Disc
column:
Results:
OrdDate | CustId | Qty | Std_Disc | Disc |
---|---|---|---|---|
5/8/17 | C001 | 4 | 0.05 | 0 |
5/9/17 | C002 | 11 | 0.05 | 0.05 |
5/10/17 | C003 | 4 | 0.05 | 0 |
5/11/17 | C001 | 25 | 0.05 | 0.1 |
5/12/17 | C002 | 19 | 0.05 | 0.07 |