Case statements

Case statements make use of the following syntax: CASE <expression> WHEN <value1> THEN <return1> WHEN <value2> THEN <return2> ... ELSE <default return> END.

In case statements, the value of the expression is matched to each of the values and whenever a match is found, the return value corresponding to it is returned. If no value matches the expression, then the default else value is returned. If there is no default value, null values will be returned.

Case statements are very useful when you have to compare the same expression against multiple values. An example would be if we wanted to assign numbers to some of the markets. We can create a calculation as shown in the following screenshot:

Now, if we place both Market and Market Number next to one another, we can see the groups:

 As an independent exercise, create a case statement giving each day of the week a number.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.132.137