Early Access: The content on this website is provided for informational purposes only in connection with pre-General Availability Qlik Products. All content is subject to change and is provided without warranty.
The unless prefix and suffix
is used for creating a conditional clause which determines whether a statement
or exit clause should be evaluated or not. It may be seen as a compact
alternative to the full if..end if
statement.
The statement or the exitstatement will only be executed
if condition is evaluated to
False.
The unless prefix may be used
on statements which already have one or several other statements, including
additional when or unless
prefixes.
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.
When to use it
The Unless statement returns a Boolean result. Typically, this type of function will be used as a condition when the user would like to conditionally load or exclude parts of the script.
The following lines show three examples of how the Unless function may be used:
exit script
unless A=1;
unless A=1
LOAD * from myfile.csv;
unless A=1
when B=2 drop table Tab1;
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 regional settings for apps and scripts.
Default regional settings in apps are based on the user profile. 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.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
id
date
amount
Results table
id
date
amount
1
08/30/2018
23.56
2
09/07/2018
556.31
3
09/16/2018
5.75
4
09/22/2018
125.00
5
09/22/2018
484.21
6
09/22/2018
59.18
7
09/23/2018
177.42
Because the variable A is assigned the value of 1 at the start of the script, the condition following the Unless prefix is evaluated, returning a result of FALSE. As a result, the script continues to run the Load statement. In the results table, all the records from the Transactions table can be seen.
If this variable value is set to equal to 2, no data will be loaded into the data model.
The load script starts by loading an initial dataset into a table named Transactions. The script is then terminated unless there are less than 10 records in the Transactions table.
If this condition does not result in a termination of the script, a further set of transactions is concatenated into the Transactions table and this process is repeated.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
id
date
amount
Results table
id
date
amount
1
08/30/2018
23.56
2
09/07/2018
556.31
3
09/16/2018
5.75
4
09/22/2018
125.00
5
09/22/2018
484.21
6
09/22/2018
59.18
7
09/23/2018
177.42
8
10/01/2018
164.27
9
10/03/2018
384.00
10
10/06/2018
25.82
11
10/09/2018
312.00
12
10/15/2018
4.56
13
10/16/2018
90.24
14
10/18/2018
19.32
There are seven records in each of the three datasets of the load script.
The first dataset (with transaction id 1 through 7) is loaded into the application. The Unless condition evaluates whether there are less than 10 rows in the Transactions table. This evaluates to TRUE, and therefore the second dataset (with transaction id 8 through 14) is loaded into the application. The second Unless condition evaluates if there are less than 10 records in the Transactions table. This evaluates to FALSE, and so the script terminates.
Example 3 – Multiple Unless prefixes
Overview
Open the Data load editor and add the load script below to a new tab.
In this example, a dataset containing one transaction is created as a table called Transactions.
A 'for' loop is then triggered, in which two nested unless statements evaluate:
Unless there are more than 100 records in the Transactions table
Unless the number of records in the Transactions table is a multiple of 6
If these conditions are FALSE, a further seven records are generated and concatenated onto the existing Transactions table. This process is repeated until one of the two transactions returns a value of TRUE.
Load script
Transactions:
Load
0 as id
Autogenerate 1;
For i = 1 to 100
unless NoOfRows('Transactions') > 100 unless mod(NoOfRows('Transactions'),6) = 0
Concatenate
Load
if(isnull(Peek(id)),1,peek(id)+1) as id
Autogenerate 7;
next i
Results
Load the data and open a sheet. Create a new table and add this field as a dimension:id.
Results table
id
0
1
2
3
4
5
+30 more rows
The nested unless statements that occur in the 'for' loop evaluate the following:
Are there more than 100 rows in the Transactions table?
Is the total number of records in the Transactions table a multiple of 6?
Whenever both unless statements return a value of FALSE, a further seven records are generated and concatenated onto the existing Transactions table.
These statements return a value of FALSE five times, at which point there are a total of 36 rows of data in the Transactions table.
After this, the second Unless statement returns a value of TRUE, and therefore the load statement following this will no longer be executed.
Dataset
The term dataset is sometimes synonymous with table. It can refer to the original source table, the table after undergoing transformations, or the fact and dimension tables in a data mart.
It can also refer to a logical table, where there are several instance tables and views:
Current data
History, which holds previous versions of the table
The load script is a sequence of statements that defines what data to load and how to link the different loaded tables. It can be generated with the Data manager, or with the Data load editor, where it also can be viewed and edited.