Qlik Community

Ask a Question

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

Announcements
Talk to Experts Tuesday, January 26th at 10AM EST: Qlik Sense. REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
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

3 Replies
Partner
Partner

Hi, 

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

Regards,

Prashant

Creator
Creator

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.

Partner
Partner

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