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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
sumanta12
Creator II
Creator II

for loop issue

Hi All,

I have a data like below:

DateName
17-Aug-2020Phillip Summers
18-Aug-2020Quamar Tran
19-Aug-2020Daquan Gray
20-Aug-2020Nasim Rodriguez
21-Aug-2020Ryder Bryant
22-Aug-2020Galvin Hays
23-Aug-2020Austin Navarro
24-Aug-2020Dieter Padilla
25-Aug-2020Nissim Vargas
26-Aug-2020Calvin Rosales
27-Aug-2020Lance Hensley
28-Aug-2020Ethan Odonnell
29-Aug-2020Oscar Harmon
30-Aug-2020Ira Moore
31-Aug-2020James Mitchell

 

Now I want to load data for each date and store it in each qvd and I have written the below script:

TMP_TABLE:
LOAD
DATE(Date,'DD-MMM-YYYY') AS Date,
Name
FROM
[C:\Users\smandal\Downloads\Test.xls]
(biff, embedded labels, table is Worksheet$);

FOR i =0 TO (NOOFROWS('TMP_TABLE')-1)

LET v_data = PEEK('Date',i,'TMP_TABLE');

NOCONCATENATE
TABLE:
LOAD * RESIDENT TMP_TABLE
WHERE Date = '$(v_data)';

STORE TABLE INTO C:\Users\smandal\Downloads\$(v_data)_TEST.QVD(QVD);

NEXT i

 

But it is not working. The code is generating qvd from 17-Aug-2020 to 31-Aug-2020 but data in the qvd is same for all.

 

Please help.

2 Replies
haskia
Partner - Contributor III
Partner - Contributor III

You code looks fine. You should add a "drop table" at the end of each iteration of the for-loop. Just before calling "next". 


I have tried to rebuild your app and traced v_data with the following command. It was empty. 

Trace 'v_data: $(v_data)'

 Make sure Date in your source file is an actual valid date field. It worked when I replaced Date() with Date#().

Here's the full code:

SRC:
LOAD * INLINE [
Date, Name
17-Aug-2020, Phillip Summers
18-Aug-2020, Quamar Tran
19-Aug-2020, Daquan Gray
20-Aug-2020, Nasim Rodriguez
21-Aug-2020, Ryder Bryant
22-Aug-2020, Galvin Hays
23-Aug-2020, Austin Navarro
24-Aug-2020, Dieter Padilla
25-Aug-2020, Nissim Vargas
26-Aug-2020, Calvin Rosales
27-Aug-2020, Lance Hensley
28-Aug-2020, Ethan Odonnell
29-Aug-2020, Oscar Harmon
30-Aug-2020, Ira Moore
31-Aug-2020, James Mitchell
];

TMP_TABLE:
NoConcatenate LOAD DISTINCT
DATE#(Date,'DD-MMM-YYYY') AS Date,
Name
RESIDENT SRC;
drop table SRC;

FOR i = 0 TO NOOFROWS('TMP_TABLE')-1

LET v_data = PEEK('Date',i,'TMP_TABLE');


trace 'v_data: $(v_data)';
trace $(v_data);


NOCONCATENATE
TABLE:
LOAD * RESIDENT TMP_TABLE
WHERE Date = '$(v_data)';

STORE TABLE INTO lib://DEV/$(v_data)_TEST.QVD(QVD);
drop TABLE;

NEXT i