CASE Statements
CASE
statements are similar to IF
statements, but instead of creating outputs based on tests, the values within an expression are evaluated, and if they match with a given value, then the statement outputs the corresponding result. The WHEN
, THEN
, ELSE
, and END
keywords are required and CASE
statements are formatted as follows:
CASE expr
WHEN value1 THEN output1
[WHEN value THEN output]
[ELSE defaultoutput]
END
An example using the field with the values 1, null
, and 3 is given here:
CASE [Field]
WHEN 1 THEN 1
WHEN 3 THEN -3
ELSE 0
END
This would return 1 for the value 1, 0 for the null
value, and -3 for the value 3.
Writing a CASE Statement
In this section, you will create a CASE
statement. This will help you understand the difference in syntax when compared to an IF
statement.
- On a new sheet, show the Top Customer parameter by right-clicking it at the bottom of the Data pane and selecting Show Parameter. It is now displayed...