Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Switch case example

hi,

i am using qlik sense desktop and i want to see example of using Switch..case..default..end switch as it is very helpful in creating the reports.

2 Replies
dberkesacn
Partner - Creator III
Partner - Creator III

Hi, have you seen the help, it has a really good example.

     Switch..case..default..end switch ‒ Qlik Sense

Example:

Switch I

Case 1

LOAD '$(I): CASE 1' as case autogenerate 1;

Case 2

LOAD '$(I): CASE 2' as case autogenerate 1;

Default

LOAD '$(I): DEFAULT' as case autogenerate 1;

End Switch

Daniel

Lemac
Contributor III
Contributor III

After a while, it finally clicked how it worked for me. Allow me to share this example; I use switch to define a variable depending on whether or not the variable 'vSchemaName' is filled. 

 

Let vLenSchemaName=len('$(vSchemaName)'); //I create a variable, measuring the length of the  schemaname.

Switch vLenSchemaName 
    case 0 //So, there is no schemaname, the value of the 'switch'-variable is 0.
            Let vTableNameCaps=UPPER('$(vTableNamePrefix)$(vTableName)' );
    default //So, there is a schemaname; 
            Let vTableNameCaps=UPPER('$(vTableNamePrefix)$(vSchemaName)_$(vTableName)' );

end switch;