Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

loop by period value

Hi, I'm new here.

Could you please help me with a script for loop and the required variables?

I have a table with period data and i need to create a file for each period:

Table:

Load

     A,

     B,

     Period

From test.qvd

Period is in form 201608 and the files need to be named: test_year_month.qvd

The result tables should be e.g.:

Table2:

     A,

     B,

     A+B,

     Period

From test_2016_08.qvd

Once I have files for each period I need to modify the script so that it runs only for the last three periods.

Many thanks for help guys

Tommy

1 Solution

Accepted Solutions
Gysbert_Wassenaar

Oops, forgot to drop the table Temp after storing it. Add a line below the store:

DROP TABLE Temp;


talk is cheap, supply exceeds demand

View solution in original post

3 Replies
Gysbert_Wassenaar

Perhaps like this:

Periods:

LOAD Period FROM test.qvd (qvd);

LET vPeriodCount = FieldValueCount('Period','Periods');

 

FOR i = 1 TO $(vPeriodCount)

     LET vPeriod = FieldValue('Period', $(i));

     LET vMonth = Right('$(vPeriod)',2);

     LET vYear = Left('$(vPeriod)',4);

     Temp:

     LOAD

          A, B, A+B, Period

     FROM

          test.qvd (qvd)

     WHERE

          Period = $(vPeriod);

    

     STORE TABLE Temp INTO [test_$(vYear)_$(vMonth)] (qvd) ;

NEXT

DROP TABLE Periods;


talk is cheap, supply exceeds demand
Not applicable
Author

Thanks so much.

Almost good, but one thing is still wrong. For the first QVD it is fine - only first period is taken. In the next QVD there are two periods, in the third - 3 and so on...

Can you please help?

Tommy

Gysbert_Wassenaar

Oops, forgot to drop the table Temp after storing it. Add a line below the store:

DROP TABLE Temp;


talk is cheap, supply exceeds demand