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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
mfarsln
Creator II
Creator II

Do While Loops through months

Hi,

I want to generate an inline table which populates with do while loop. What i want to achieve is like below;

 

Date          Period
09.01.2019    177
10.01.2019    178
11.01.2019    179
12.01.2019    180
01.01.2020    181

 

Dates keep going until 09.01.2021.

I am using the below script but somehow it ignores do while loop and gets nothing upon finishing.

 

let vConcat='';
let vStartDate = date('09/01/2019','MM/DD/YYYY');
let vEndDate = date('09/01/2021','MM/DD/YYYY');
let vPeriod = 177;

do while $(vStartDate)<=$(vEndDate)

$(vConcat)
period_table:
load
* inline [
date, period
$(vStartDate),$(vPeriod)
];


let $(vStartDate) = Date(AddMonths($(vStartDate),1),'MM/DD/YYYY');
let $(vPeriod) = $(vPeriod) +1;
let vConcat='Concatenate';

loop;

 

Edit: I've found it. It was because of $ dollar sign expressions.

 

 

Labels (1)
1 Solution

Accepted Solutions
sunny_talwar

You can also do this using  While loop like this

LET vStartDate = Num(Date#('09/01/2019','MM/DD/YYYY'));
LET vEndDate = Num(Date#('09/01/2021','MM/DD/YYYY'));
LET vPeriod = 177;

period_table:
LOAD MonthStart($(vStartDate), IterNo()-1) as date,
	 $(vPeriod) + IterNo() - 1 as period
AutoGenerate 1
While MonthStart($(vStartDate), IterNo()-1) <= $(vEndDate);

View solution in original post

1 Reply
sunny_talwar

You can also do this using  While loop like this

LET vStartDate = Num(Date#('09/01/2019','MM/DD/YYYY'));
LET vEndDate = Num(Date#('09/01/2021','MM/DD/YYYY'));
LET vPeriod = 177;

period_table:
LOAD MonthStart($(vStartDate), IterNo()-1) as date,
	 $(vPeriod) + IterNo() - 1 as period
AutoGenerate 1
While MonthStart($(vStartDate), IterNo()-1) <= $(vEndDate);