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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Loop Through Date and Create QVD

Hi everyone,

This is probably a simple concept but I am not all that familiar with loops.  Basically I have the following in a table, say with a date from 01/01/2013 through today 10/30/2014.


Data:

Reported_Date, Value

01/01/2013, 1.5

...

06/30/2014, 1.2

...

10/30/2014, 1.8

I would like to loop through and create a QVD for each date from 06/30/2014 and forward.  What's the best way to do this?

Thanks!

Labels (1)
5 Replies
alexandros17
Partner - Champion III
Partner - Champion III

The logic must be something like:

For i = 1 to number of rows of the table (Look for NoofRows() function)

     LET myDate=Peek(myDateField,$(i));

     MYTAB:

     noconcatenate

     Select * from MyTable where myDateField = $(myDate);

     Store * from MYTAB INTO mytab_$(myDate).qvd;

     drop table MYTAB;

Next

Let me know

Not applicable
Author

Hello Mark, Please find the below:

LOAD Reported_Date, Value From source_table :

LET vRows =

FOR i=1 to  FieldValueCount('Reported_Date')

    LET vDate = FieldValue( 'Reported_Date', $(i) );

   QVDNAME_$(vDate):

   LOAD * FROM ..(ur statement)

   STORE QVDNAME_$(vDate) FROM QVDNAME_$(vDate).qvd (qvd) ;

   DROP Table QVDNAME_$(vDate):    

Next

Not applicable
Author

Hi Alessandro - thanks for your response.  I receive the following errors and am not sure why. It appears QV is having trouble understanding the variable $(vDate) in the where clause. 

Field not found - <=>

MyTable:

NoConcatenate

LOAD * RESIDENT Data where [REPORTED_DATE]=

---------------------------------

For i = 1 to NoOfRows(Data)

LET vDate=Peek([REPORTED_DATE],$(i));

MyTable:

NoConcatenate

LOAD * RESIDENT Data where [REPORTED_DATE]=$(vDate);

Store MyTable into [DailyStats_$(vDate).qvd](qvd);

Drop Table MyTable;

Next

Anonymous
Not applicable
Author

use peek function.

alexandros17
Partner - Champion III
Partner - Champion III

try with

For i = 1 to NoOfRows(MyTable)


verify (with a text box that NoOfRows(MyTable) returns the right number