Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Generating random data for demo

I have a script that is generating random sales data between 1500 and 5000 for a range of dates as below...

TmpSalesData:
LOAD
Date($(varMinDate) + RowNo() - 1) AS DateKey,
rand()*3500 + 1500 AS RandomData
AUTOGENERATE ($(varMaxDate) - $(varMinDate)+1);

I also have a field called OUTLET in a previously loaded table. I would like to amend my script for the TmpSalesData table using FOR .. NEXT to generate random data for each combination of Date and OUTLET. I have tried a few combinations of FOR .. NEXT within and outside the load statement without success. Could someone please point me in the right direction?

Many thanks

Dave

1 Solution

Accepted Solutions
Not applicable
Author

Many thanks Rob, that is perfect.

Regards

Dave

View solution in original post

2 Replies
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Assume previously loaded table OUTLET with a field named "Outlet". Use NoOfRows('OUTLET') as the limit variable. Use peek() as the index.

Suggested code (untested)

FOR i = 0 TO NoOfRows('OUTLET') - 1
TmpSalesData:
LOAD
peek('Outlet', $(i), 'OUTLET') as Outlet,
Date($(varMinDate) + RowNo() - 1) AS DateKey,
rand()*3500 + 1500 AS RandomData
AUTOGENERATE ($(varMaxDate) - $(varMinDate)+1);
NEXT

-Rob

Not applicable
Author

Many thanks Rob, that is perfect.

Regards

Dave