Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
richard_cook
Contributor II
Contributor II

Random Sample using Slider object

I'm developing QlikView dashboards for my Internal Audit department and we must have a method by which an auditor can select random samples once they have drilled to a certain population of detail records. The method I've come up with appears to work (sometimes) but the slide bar is rather erratic. I feel pretty certain I can get it to work consistently but I need some assistance. Given the following, I need help with my Slider object and sample selection [Rank() & Rand()] working together consistently. In my example, think of the Strata being sets of data from which we would need to select random samples. Any thoughts would be greatly appreciated. Thanks!

Here's what I've done so far.

General Layout using a Slider object to select the sample size.

Overview.png

Step 1) Create a variable called vSampleSize

Create Variable.png

Step 2)  Use the vSampleSize variable in the Slider Object - General properties.

Slider Object General.png

Step 3) Assign an action to vSampleSize

Variable Action.png

Step 4) Toggle Select Action

Toggle Select.png

Step 5) Build the search string. I want to select the top n (vSampleSize) records randomly assigned using Rank() and Rand()

Search String.png

Resulting in a "Toggle Select" selection string like this:

Selection String.png

Why does the selection sometimes do this? It doesn't select.

Inconsistent.png

1 Solution

Accepted Solutions
Anonymous
Not applicable

I know this was a long time ago but I got this to work.

View solution in original post

7 Replies
Not applicable

Hi Richard,

unfortunately, I don't have an answer for you.

But I found your post really helpful for something I am trying right now.

Any chance, you figured out how to make the sample even more random? I noticed that whenever you aks for the same sample size (e.g. 10) you will always get the same 10 samples.

However, I would like to see different samples every time you change the sample size.

Would you or anyone else know how to do this?

Regards,

Daniela

Anonymous
Not applicable

Daniela,

In your scenario, the random stays the same until the app is reloaded.

To have it change each time you can multiply your Rand by now().

Anonymous
Not applicable

I know this was a long time ago but I got this to work.

richard_cook
Contributor II
Contributor II
Author

Thank You Wallo! That seems to have solved its erratic behavior and provides the sample selection I was looking for.  It was a while ago but the functionality is still fundamental to how we can use leverage QlikView in the future.

Anonymous
Not applicable

Glad it works.  As I mentioned to Daniela, if you want it to select a different random group each time, you'll need to multiply the RAND() by now().

So the vExpression becomes

'=rank(rand()*now()*100)<($(vSampleSize)+1)'

Otherwise, you'll only get a different random selection when the app is reloaded.

richard_cook
Contributor II
Contributor II
Author

Which is exactly what I needed! Exactly! That's just perfect!

richard_cook
Contributor II
Contributor II
Author

Daniela,

Wallo's solution and addendum below perform the functionality both you and I were looking for.

I hope it helps you!

Thanks!

Ricky