Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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;
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;
@stevejoyce Thanks, worked like a charm.
I just have a question, where does the rowno() join on.
Kind regards,
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.