Qlik Community

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

Highlighted
mfarsln
Contributor

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

Re: Do While Loops through months

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

Re: Do While Loops through months

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