The First prefix to a LOAD or SELECT (SQL) statement is used for loading a set maximum number of records from a data source table. A typical use case for using the First prefix is when you want to retrieve a small subset of records from a large and/or slow data load step. As soon as the defined “n” number of records has been loaded, the load step terminates prematurely, and the rest of the script execution continues as normal.
First n ( loadstatement | selectstatement )
|n||An arbitrary expression that evaluates to an integer indicating the maximum number of records to be read. n can also be enclosed in parentheses: (n).|
|loadstatement | selectstatement||The load statement/select statement that follows the n argument will define the specified table that must be loaded with the set maximum number of records.|
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.
Default regional settings in apps are based on the regional system settings of the computer or server where Qlik Sense is installed. If the Qlik Sense server you are accessing is set to Sweden, the Data load editor will use Swedish regional settings for dates, time, and currency. These regional format settings are not related to the language displayed in the Qlik Sense user interface. Qlik Sense will be displayed in the same language as the browser you are using.
|FIRST 10 LOAD * from abc.csv;||This example will retrieve the first ten lines from an excel file.|
|FIRST (1) SQL SELECT * from Orders;||This example will retrieve the first selected line from the Orders dataset.|
Example – Load the first five rows
Open the Data load editor and add the load script below to a new tab.
The load script contains:
A dataset of dates from the first two weeks of 2020.
The First variable that instructs the application to only load the first five records.
Sales: FIRST 5 LOAD * Inline [ date,sales 01/01/2020,6000 01/02/2020,3000 01/03/2020,6000 01/04/2020,8000 01/05/2020,5000 01/06/2020,7000 01/07/2020,3000 01/08/2020,5000 01/09/2020,9000 01/10/2020,5000 01/11/2020,7000 01/12/2020,7000 01/13/2020,7000 01/14/2020,7000 ];
Load the data and open a sheet. Create a new table and add Date as a field and sum(sales) as a measure:
The script only loads the first five records of the Sales table.