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

Loops involving Tables or Data Pulled into The Mode

I am Loading a table of 4 Colums (With Data), i now need to add to this table but to add to it i need to run a loop (For ...To),

a) can this be done?

b) if so can someone help me with the code.

4 Replies
johnw
Champion III
Champion III

a) yes
b) I don't understand your requirement. What do you MEAN by "add to this table"? What are you adding? Rows? Columns? What is your source for what you're adding? What is the loop supposed to do for you?

Not applicable
Author

Hi John,

Thanks,

the last entry in the table will be something like this:

X 200910 abc def

I need to create a loop that replicates this row but changes the period (200910) till the current period (201006), then places those records back into the same table.

Does that make sense, i am really new to qlikview, so please bear with me.

Thanks

johnw
Champion III
Champion III

There's probably a more clever way, and I'm not sure this is completely correct, but maybe something like this:

[NewRows]:
LOAD max(Month) as Month // figure out the maximum month in your data
RESIDENT Data
;
INNER JOIN ([NewRows]) // grab the other fields for this month
LOAD *
RESIDENT Data
;
RENAME Month TO MaxMonth
;
LEFT JOIN ([NewRows])
LOAD date(addmonths(MaxMonth,iterno()),'YYYYMM') as Month
AUTOGENERATE 1
WHILE addmonths(MaxMonth,iterno()) <= today() // this is the loop
;
DROP FIELD MaxMonth
;
CONCATENATE ([Data]) // add the new rows back to the other table
LOAD *
RESIDENT [NewRows]
;
DROP TABLE [NewRows] // and get rid of the temporary table
;

Not applicable
Author

thanks