Skip to main content

When

The when prefix and suffix is used for creating a conditional clause which determines whether a statement or exit clause should be executed or not. It may be seen as a compact alternative to the full if..end if statement.

Syntax:  

(when condition statement | exitstatement when condition )

Return data type: Boolean

In Qlik Sense, the Boolean true value is represented by -1, and the false value is represented by 0.

The statement or the exitstatement will only be executed if condition is evaluated to TRUE.

The When prefix may be used on statements which already have one or several other statements, including additional When or Unless prefixes.

The When statement returns a Boolean result. Typically, this type of function will be used as a condition when the user would like to load or exclude parts of a script.

Arguments
Argument Description
condition A logical expression evaluating to TRUE or FALSE
statement Any Qlik Sense script statement except control statements.
exitstatement An exit for, exit do or exit sub clause or an exit script statement.

Regional settings

Unless otherwise specified, the examples in this topic use the following date format: MM/DD/YYYY. The date format is specified in the SET DateFormat statement in your data load script. The default date formatting may be different in your system, due to your regional settings and other factors. You can change the formats in the examples below to suit your requirements. Or you can change the formats in your load script to match these examples. For more information, see Modifying app regional settings.

Default regional settings in apps are based on a combination of identity provider settings, system settings, or browser settings. These regional format settings are not related to the language displayed in the Qlik Cloud user interface. Qlik Cloud will be displayed in the same language as the browser you are using.

If you are an app creator, you can set the default region for apps you create. For more information, see Setting your preferred regional settings for creating apps.

Function examples
Example Result
exit script when A=1; When the statement A=1 is evaluated to be TRUE, the script will stop.
when A=1 LOAD * from myfile.csv; When the statement A=1 is evaluated to be TRUE, the myfile.csv will be loaded.
when A=1 unless B=2 drop table Tab1; When the statement A=1 is evaluated to be TRUE, and if B=2 is evaluated to be FALSE, than the Tab1 table will be dropped.

Example 1 – When prefix

Example 2 – When suffix

Example 3 – Multiple When prefixes