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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Problem whit month iteration (for...next)

Hello, i need to (monthly) iterate from InitMonth to ActualMonth but this code doesn't work

LET vActualMonth = Num(MonthStart(Today()));

LET vInitMonth = Num(MonthStart(AddMonths(vActualMonth, -2)));

FOR vLoopMonth = vInitMonth to vActualMonth step AddMonths(vLoopMonth, 1)

.

.

.

...

NEXT

Any help please?

If i skip the step expression i can iterate daily but i want to get a monthly iteration.

1 Reply
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

The step expression is only evaluated once and it is an increment, so that approach won't work. Here's another approach.

LET vActualMonth = Num(MonthStart(Today()));

LET vInitMonth = Num(MonthStart(AddMonths(vActualMonth, -2)));

FOR i = 0 to 2

          LET vLoopMonth = AddMonths($(vInitMonth), $(i));

          // Do something with vLoopMonth

NEXT i

-Rob

http://robwunderlich.com