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: 
Anonymous
Not applicable

Issue with For Loop

Hi,

I am trying to load all the months prior to this month for the calendar year. I have written the following logic but i am not getting the desied result. Example, current month is November. So, i will have to load all the previous months from Jan to Oct.

Let vDateToday = Num(today());

Let TotalMonths= (Num(Month($(vDateToday))) -1);

for i = 1 to $(TotalMonths)

    Load Text(Month(MakeDate(Year($(vDateToday)),($(i))))) as CalendarMonthsCompleted;

next i ;

Please help

Labels (1)
7 Replies
Anonymous
Not applicable
Author

Also this script is just loading only one value which is Jan

sunny_talwar
MVP
MVP

Are you trying to create a table which only include 1 month less than current month? May be like this

Table:

LOAD Month(AddMonths(YearStart(Today()), IterNo()) as CalendarMonthsCompleted

AutoGenerate 1

While IterNo() < Num(Month(Today());

Anonymous
Not applicable
Author

Exactly Sunny. I tried your logic. But it takes from Feb because of Iterno() starting from 1

Anonymous
Not applicable
Author

the requirement is to exclude the current month and include all the months prior to it. That is from Jan to Oct

sunny_talwar
MVP
MVP

‌my bad... try this

Table:

LOAD Month(AddMonths(YearStart(Today()), IterNo() - 1) as CalendarMonthsCompleted

AutoGenerate 1

While IterNo() < Num(Month(Today());

Anonymous
Not applicable
Author

Thanks Sunny. That worked

MarcoWedel
MVP
MVP

Hi,

one solution might be also:

QlikCommunity_Thread_240376_Pic1.JPG

LOAD Month(Date#(RecNo(),'M')) as Month

AutoGenerate Month(Today())-1;

hope this helps

regards

Marco