Every Friday at Bitmetric we’re posting a new Qlik certification practice question to our LinkedIn company page. Last Friday we asked the following Qlik Data Architect certification practice question about Qlik subset creation in load scripts:

While many people knew about loading data subsets using *First*, it was clear that the *Sample *prefix is a lot less known.

### The correct answer is D: Random 10% of total rows are loaded from Customer.QVD

Arguably one of the most encountered problems during development is long loading times of (very) large datasets. In order to speed up development it is obviously nice to be able to create a subset in the load of the dataset. There are various ways of doing this, but looking at the comments and answers to the question, First is one which came to mind by many.

First is a prefix which limits the load to a specified number of rows. For example *First 1000* will limit the load to the first 1000 rows from the table. Making the load and thus the development time quicker.

## So what is the catch?

However, in some cases it could be that loading the first rows doesn’t cut it. For example:

- The first rows of the dataset are filled with data of questionable quality (empty rows or test data)
- Data is sorted on alphabet and only name records starting with A are loaded
- Dates. The data could be sorted on entrydate and you only load the first dates from the dataset

Especially that last example makes sense if we are looking into front-end results. How do we compare year to date measures or point in time reporting if we only load a few dates? Take the following example dashboard from a car sales company. In this example we have used *First 1000* as a prefix.

We can clearly see that there is data in the dashboard, but that most of the charts and KPI objects are not really telling us much. In this way we cannot check whether the measures are performing as expected.

Now using an equivalent sized Sample load, in this case using *Sample (0.1)* as prefix we get the following result:

This dashboards speaks more to the imagination, giving us a better look at all the various data. Since we now have data randomly picked from the total dataset we can immediately see that year to date and in time measures are performing as expected.

## So how do I use Sample?

The sample prefix has the following syntax:

**Sample** p ( loadstatement | selectstatement )

The p argument is to indicate the probability that a record is read. It is optional to put this amount in parentheses. So looking at the example from the question we can tell that a random 10% is added to the loaded dataset.

## Things to keep in mind?

*Sample*will look through the entire dataset. First will limit it to a fixed row number and stop. This means that sample could potentially still be slower.- Every time you reload again the sample set will change. Keep that in mind.
- Each row is evaluated separately. So with
*Sample (0.1)*each row will have 10% chance to end up in the resulting table. This means that if you load a dataset consisting of 1000 rows, it will on average load 100 rows into the table, but for each iteration this could deviate a little bit, since it will go through the total dataset and evaluate each row on 10%. *Sample*must be a value between 0 and 1.- Combining
*First*and*Sample*is possible. - Wait what?

## Combining first and sample

Yes it is possible to combine both prefixes. Should you and what does it do? Let’s have a look at the results first to understand what is happening. The following load script is used:

FIRST 1000

SAMPLE (0.1)

LOAD

*

FROM [LIB:\\Customers.qvd]

(qvd);

After this load we also have loaded *Sample (0.2)*, *Sample (0.3)* and so on, untill *Sample (1)*. If we then check the resulting data models record and row numbers we see the following results:

As we can see the load is limited to 1000 rows, but still random sampled. There is no difference in order of these prefixes. So it doesn’t matter if we use first and then sample or sample and then first. However the logical conclusion of First 1000 Sample (0.1) would be that Qlik would load the first 1000 rows and then samples 10% of these, giving us probably 100 rows as result. But this is not the case.

When combining first and sample the order doesn’t matter. Qlik will always evaluate sample first and then limit this load to the first 1000 samples. As we can see in the table above this is as expected. Sample(1) will result in a 100% chance for each row to return. This gradually moves to a bigger sample with how less the chance is a record is added. So sample (0.1) means that each row has a 10% chance of being added to the data model. First 1000 tells the load script to stop at row 1000, which could be a higher record number because of the chance of addition.

So should you use this? All depends on the size of the data sets and what you wish to evaluate. But if you want to do a over time analysis on a subset of data, the usage of sample should be sufficient.

**That’s it for this week. And remember:**

### Are these questions too easy for you?

If these questions are too easy for you, then you may be ready for the **Masters Summit for Qlik**.

At the Masters Summit for Qlik, we take your Qlik skills to the next level in 3 days with deep dives about:

- Qlik Data Modelling
- Qlik Scripting
- Set Analysis and Advanced Aggregations
- Solution Architecture & Performance
- Effective Visualizations
- Performance Tuning
- Qlik Sense integration

The courses are taught by Qlik veterans Rob Wunderlich, Oleg Troyanksy, Bill Lay, Nick Webster and Bitmetric’s Barry Harmsen. Together, this team brings almost 75 years of Qlik experience and has implemented hundreds of successful projects.

You can find more information and registration on the **Masters Summit for Qlik website**, or check out a photo impression of the previous edition in Madrid.

### See you next week!

- If you have suggestions for questions, we love to hear from you via
**WhatsApp**or at info@bitmetric.nl - If you’re enjoying these questions and want to work on stuff like this every day (but a bit more challenging), we’re always on the lookout for new colleagues.
**Check our job openings here**. - For more of these brain teasers,
**check out our archive of Qlik certification questions and answers**. - Want to stay up to date about everything Qlik? Then sign up for our newsletter at the top of this page.