The switch control statement can be used in the script to identify a specific execution path. With the switch control statement, several paths can be defined and a default path can be defined as well when no match is found in the case clause. The various script paths cannot cross – they should be individual paths that do not overlap. In the script below, the expression x will be compared to each case. When there is a match, the script for that case will be executed.
In the example below, Case 1 will be executed – the variable y will be set to Sunday and one record will be generated in the table.
Below is a look at the record generated.
It is also possible to have more than one value for a case, for instance, you can use the script below to run the same script if x matches 1, 2 or 3.
When faced with various script execution paths, try using the switch control statement. While I rarely have a need to use it, I like how neat and straight-forward the syntax is. I have attached an example Qlik Sense app with the full script for you to test out for yourself.