The CASE function allows you to perform multiple conditional tests on a set of expressions within a single statement. When a test evaluates to true, a corresponding output is generated. Outputs may be a literal or expression.

For more information on the IF function, see IF Function.

Example:

Output: Returns a text string based on the evaluation of the Qty column:

In the following, If the testX expression evaluates to true, then the resultX value is the output.


ArgumentRequired?Data TypeDescription
test1, test2, testnYexpressionExpression that is evaluated. Must resolve to true or false
result1, result2, result2, result_elseYstringQuoted 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.

test1, test2, testn

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 IF function. For example, you must use the double-equals signs to compare values (status == 'Ok').

 

Required?Data TypeExample Value
YesExpression that evaluates to true or false(OrderAge > 90)

result1, result2, result2, result_else

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 TypeExample Value
YesLiteral value or expression

See examples below.

Example - Basic Usage

The following data represents orders received during the week. Discounts are applied to the orders based on the following rules:

OrdDateCustIdQtyStd_Disc
5/8/17C00140.05
5/9/17C002110.05
5/10/17C00340.05
5/11/17C001250.05
5/12/17C002190.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:

OrdDateCustIdQtyStd_DiscDisc
5/8/17C00140.050
5/9/17C002110.050.05
5/10/17C00340.050
5/11/17C001250.050.1
5/12/17C002190.050.07