# Sample

The sample prefix to a LOAD or SELECT statement is used for loading a random sample of records from the data source.

Syntax:

Sample p ( loadstatement | selectstatement )

The expression that is evaluated does not define the percentage of records from the dataset that will be loaded into the Qlik Sense application, but the probability of each record that is read to be loaded into the application. In other words, specifying a value `p = 0.5` does not mean that 50% of the total number of records will be loaded, but instead that for each record there will be a 50% chance that it is loaded into the Qlik Sense application.

Arguments

| Argument | Description |
| --- | --- |
| p | An arbitrary expression<br>which valuates to a number larger than 0 and lower or equal to 1. The<br>number indicates the probability for a given record to be read.<br><br>All records will be read but only some of them will be loaded into Qlik Sense. |

## When to use it

Sample is useful when you would like to sample data coming from a large table, to understand the nature of data, distribution or field contents. As it brings a subset of data, the data loads are faster, allowing faster testing of scripts. Unlike `First`, the `Sample` function brings data from the whole table, instead of being limited to the first few rows. This can provide a more accurate representation of the data in some cases.

The following examples show two possible uses of the `Sample` script prefix:

`Sample 0.15 SQL  SELECT  * from Longtable;` `Sample(0.15) 
 LOAD * from Longtab.csv;`

## 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.

Default regional settings in applications 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.

## Example 1 – Sample from an inline table

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptPrefixes/Sample.htm)

#### Load script and results

Overview

In this example, the script loads a sample set of data from a dataset containing seven records into a table named `Transactions` from an inline table.

Load script

```
Transactions:
SAMPLE 0.3
LOAD 
* 
Inline [
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
];
```

Results

Load the data and open a sheet. Create a new table and add these fields as dimensions:

* `id`

* `amount`

Add the following the measure:

`=sum(amount)8`

Results table

| id | date | =Sum(amount) |
| --- | --- | --- |
| 2 | 09/07/2018 | 556.31 |
| 4 | 09/22/2018 | 125 |
| 1 | 08/30/2018 | 23.56 |
| 3 | 09/16/2018 | 5.75 |

In the iteration of the load used in this example, all seven records were read, but only four records were loaded into the data table. Any re-run load could result in a different number, and a different set of records being loaded into the application.

## Example 2 – Sample from an autogenerated table

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptPrefixes/Sample.htm)

#### Load script and results

Overview

In this example, using `Autogenerate`, a dataset of 100 records is created with the fields `date`, `id`, and `amount`. However, the `Sample` prefix is used, with a value of 0.1.

Load script

```
SampleData:
Sample 0.1
LOAD
RecNo() AS id,
MakeDate(2013, Ceil(Rand() * 12), Ceil(Rand() * 29)) as date,
Rand() * 1000 AS amount

Autogenerate(100);
```

Results

Load the data and open a sheet. Create a new table and add these fields as dimensions:

* `id`

* `amount`

Add the following the measure:

Results table

| id | date | =Sum(amount) |
| --- | --- | --- |
| 48 | 9/28/2013 | 763 |
| 20 | 5/15/2013 | 752 |
| 19 | 11/8/2013 | 657 |
| 25 | 3/24/2013 | 522 |
| 27 | 8/23/2013 | 389 |
| 81 | 6/1/2013 | 53 |
| 100 | 8/15/2013 | 17 |

In the iteration of the load used in this example, seven records were loaded from the created dataset. Once again, any re-run load could result in a different number, and a different set of records being loaded into the application.

## Learn more

* [Load](https://help.qlik.com/en-US/sense/May2026/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptRegularStatements/Load.htm)
* [Select](https://help.qlik.com/en-US/sense/May2026/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptRegularStatements/Select.htm)