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: 
Not applicable

Looping through table and creating Dynamic columns

I have the following table ORDER

CUST_IDORD_YEARAmount
A200810
A200815
A200915
A201020
A20125
A201410
A201420
B200810
B20085
B200825
B200930
B20135
B201310
B20145

Would like to create a summary table as shown below ORD_SUMM

CUST_ID200820092010201220132014
A2515205 30
B4030 155

Tried the for loop but its throwing error.

Let vYRVal = min(ORD_YEAR);

for i=min(ORD_YEAR) to year(Today(0))

ORD_SUMM:

load

    CUST_ID,

    SUM(Amount) as $(vYRVal)

Resident

    ORDER

where

    ORD_YEAR = $(vYRVal)

group by

    CUST_ID;

vYRVal = $(vYRVal)+1;

next

drop table ORDER;

Any Idea on how to do this?

15 Replies
Not applicable
Author

Thanks Gysbert!

Still the back end data has multiple records

Anonymous
Not applicable
Author

Makes sense.

(BTW, you don't need to group by $(i) anymore, although no harm either.)

The only remaining question is what to do with the dynamic front end.

Not applicable
Author

That helps even better for 2011 there were no data and now I have blank column for that .

Not applicable
Author

This is mostly  1 time deal. But I have similar reports where I dont use year as column name rather the difference between the current year and order year prefixed with YR as column name and the title for YR_0 ( which is 2014)  will be year(Today()) and for YR_1 (i.e 2013) will be (year(Today())-1) and so forth. The table is limited to past 5 years.

Gysbert_Wassenaar

Are you sure you opened the correct version? Perhaps saving it under a different name helps.


talk is cheap, supply exceeds demand
Not applicable
Author

Sorry, I was looking at the old one..