Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
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

7 Replies
Anonymous
Not applicable
Author

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

sunny_talwar

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

‌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

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