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

Announcements
Only at Qlik Connect! Guest keynote Jesse Cole shares his secrets for daring to be different. Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
sowmi
Creator
Creator

Using For Loop

Hi everyone ,

I'm using for loop when loop runs date variables should be updated here is the scrip i am using below script but variables are updated but in my min-max table it is only showing the first start two dates in my dates file i have dates like 1/2/16,1/9/16,1/16/16

Tmp:
Load Date from file1
;


FOR i =1 to FieldValueCount('Date')-1

LET vDate_0 = Peek('Date', $(i),'Tmp');

LET vDate_1 = WeekStart(vDate_0+7); 

 

Min_Max:
Load
Date( '$(vDate_1)') as Max_Date,
Date('$(vDate_0)') as Min_Date
Resident  Tmp;
NEXT i;

 

when i run the loop i am excepting to see Max_Date as 1/16/16 and min date as 1/9/16.

 

Thnxs

Sowmi

Labels (2)
3 Replies
Prashant_Naik
Partner - Creator II
Partner - Creator II

Hi, 

Can you provide us a sample data and expected result from it, then it will be more clear to write script.

Regards,

Prashant

sowmi
Creator
Creator
Author

Hi ,

Date is weekly based starting from 1/4/2016 to 12/26/2016 ,when first loop runs min date should be 1/4/2016 and max should be 1/11/2016  min and max values should be changing when loop runs and needs to be stored in a variable so i can use them for further calculations.

Prashant_Naik
Partner - Creator II
Partner - Creator II

Hi,

This might help

Tmp:
Load distinct Date from file1
;

Let vNoofrows = NoOfrows ('Tmp');
FOR i =1 to $(vNoofrows)-1

LET vDate_0 = Peek('Date', $(i),'Tmp');

LET vDate_1 = WeekStart(vDate_0+7); 

 

Min_Max:
Load

Date,
Date( '$(vDate_1)') as Max_Date,
Date('$(vDate_0)') as Min_Date
From file1 where Date = '$(vDate_0)';
NEXT i;

Drop table TMP;

This will loop so many times which will hit the performance.

Regards,

Prashant