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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Kain_F
Contributor III
Contributor III

For loop

Hey guys and gils,

 

I have the data below 

ORGANISATION INFO NUMBER
X 1 1
Y 1 2
Z 1 3

 

What I want to do is the following:

For each organisation generate 5 new rows in a new column or field

 

So my output would be:

ORGANISATION INFO AUTOGENERATED
X 1 1
X 1 2
X 1 3
X 1 4
X 1 5
Y 1 1
Y 1 2
Y 1 3
Y 1 4
Y 1 5
Z 1 1
Z 1 2
Z 1 3
Z 1 4
Z 1 5

I have been thinking so much about this but cant get my thoughts organized.

 

Thanks in advance

Labels (1)
1 Solution

Accepted Solutions
stevejoyce
Specialist II
Specialist II

I don't see you need a forloop, you can just join an autogenerate(5) table with your input table.

 

source_data:
load
*

from https://community.qlik.com/t5/New-to-Qlik-Sense/For-loop/td-p/1858785

(html, utf8, embedded labels, table is @1)
;


left join (source_data)
load rowno() as AUTOGENERATED
autogenerate(5)
;

exit script;

View solution in original post

3 Replies
stevejoyce
Specialist II
Specialist II

I don't see you need a forloop, you can just join an autogenerate(5) table with your input table.

 

source_data:
load
*

from https://community.qlik.com/t5/New-to-Qlik-Sense/For-loop/td-p/1858785

(html, utf8, embedded labels, table is @1)
;


left join (source_data)
load rowno() as AUTOGENERATED
autogenerate(5)
;

exit script;

Kain_F
Contributor III
Contributor III
Author

@stevejoyce  Thanks, worked like a charm.

I just have a question, where does the rowno() join on.

Kind regards,

 

stevejoyce
Specialist II
Specialist II

What do you mean by where does it join on?

The 2nd table is creating a 5 row table (autogenerate(5)) with values 1-5 in a field called AUTOGENERATED (using rowno()).  I am joining this to the source table, but because there are no fields in common, it's creating a cartesian product.  so every record in the first table is gets repeated for each record in second table.