Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
TomBond77
Specialist
Specialist

Split a date to week

Hi experts

I wrote the following code with LOOP logic with WEEK to split the load volumne.  Executing the script the loop is completely ignored, no data are loaded. Any ideas how to correct the script?

Main area:

// calculate last 2 month and current month:

Let vLoadDateStart = MonthStart(makedate(Year(today()),Month(today())-2));
Let vLoadDateEnd = MonthEnd(Today());

Start Loop:

Set vLoadDate = $(vLoadDateStart);
Do while vLoadDate < vLoadDateEnd
Let vLoadWeek = Week(vLoadDate);

Loading script:

Load * from

.....

VARIABLES (
[NAME=0CALWEEK, SIGN=I, OPTION=EQ, LOW=$(vLoadWeek)],
)  //0CALWEEK has the format YYYYWW

Loop end date:

let vLoadDate = week('$(vLoadDate)')+1;
loop

 

 

Labels (5)
2 Replies
Or
MVP
MVP

I'd suggest running in debug mode and seeing what gets populated / handled correctly and what does not.

Off the top of my head, the first variable is clearly incorrect. Month(Today()) -2 results in negative 1 (January = 1, and then subtract two). Use AddMonths() instead of subtraction.

TomBond77
Specialist
Specialist
Author

Thanks, can you please send the AddMonths code for the first part? Thank you.