Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
rodrigue_saade
Partner - Creator
Partner - Creator

Generate Random Data from Specific Values

Hi,

In the script, is it possible to generate random data in a field named "X" for example, from the VALUES of another field named "Y"?


6 Replies
alexandros17
Partner - Champion III
Partner - Champion III

Yes, you can decide the rule to generate random values according to the type of the starting field.

If the field is numeric you can use Rand(function), if the field is a string you can use the first char numerical value, if the field is a date you can use its numerical representation

danieloberbilli
Specialist II
Specialist II

maybe sth like

Pick(Ceil(3*Rand()),'A','B','C') as MyRandomField1,

or with the field Y

Round(1000*Rand()*Rand()*Y) as MyRandomField2,

rodrigue_saade
Partner - Creator
Partner - Creator
Author

The case is the following:

i have the field Y having the values as in the screenshot:

Capture.PNG

I need to create a new table with the following:

LOAD id,

          <random values from the values in Field Y>  as Field X

[.....]

Not applicable

Hi what type of random value do you need like String or number type.

In QLikview we can generate the random data , but we need a pattern to generate the random data.

What is ur assumption or pattern for FieldX with respect FieldY.

Generally we use rand function to generate the number type.

Ceil(RAND()*100)

taha_mansoor
Creator
Creator

Thanks, very useful. What in case I want to generate the values in the ratio of my choice, e.g., I am generating 1000 rows with values A, B, C and I want to populate 30% with value A, 50% with value B and 20% with value C. Can I do that?

I am referring to this code: Pick(Ceil(3*Rand()),'A','B','C') as MyRandomField1

MarcoWedel

Hi,

maybe one solution might be:

QlikCommunity_Thread_169773_Pic1.JPG

table1:

LOAD RecNo() as ID, * Inline [

FieldY

A344534

B346564

C345645

D457675

E435645

F352356

G435756

];

table2:

LOAD ID,

    FieldValue('FieldY',Ceil(Rand()*FieldValueCount('FieldY'))) as FieldX

Resident table1;

hope this helps

regards

Marco