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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
wunderch
Creator II
Creator II

do while with if statement

Hi Guys,

I have a problem with do while and an if statement.

I want to load Data from 5 Years ago to today, but on 01.01. the Data should be load from 5 years ago to year(today)-1, because on 01.01. I haven't Data from the actual year.

Example:

LET a=year(today())-5;

if num(month(Today()))=01 and day(today())=01 then

do while a<=year(today())-1;

ELSE

do while a<=year(today());

TEST:

Load

*

from TEST_(a).csv;

LET a=a+1;

Loop

ENDIF;

 

How can I do this????

Regards Chris

 

Labels (1)
1 Solution

Accepted Solutions
Frank_Hartmann
Master II
Master II

Maybe like this:

 

 

if num(month(Today()))=1 and num(day(today()))=1 then
For a = year(today())-5 to year(today())-1;
TEST$(a):
Load
*, FileName() as Filename
FROM
[Test_$(a).csv];
next a;
ELSE
For b = year(today())-5 to year(today())
TEST$(b):
Load
*, FileName() as Filename
FROM
[Test_$(b).csv];
next b;
endif;

 

 

View solution in original post

3 Replies
Frank_Hartmann
Master II
Master II

Maybe like this:

 

 

if num(month(Today()))=1 and num(day(today()))=1 then
For a = year(today())-5 to year(today())-1;
TEST$(a):
Load
*, FileName() as Filename
FROM
[Test_$(a).csv];
next a;
ELSE
For b = year(today())-5 to year(today())
TEST$(b):
Load
*, FileName() as Filename
FROM
[Test_$(b).csv];
next b;
endif;

 

 

wunderch
Creator II
Creator II
Author

Hi Frank,

thanks for your quick answer.

Yes this works!

Have a nice day!

Chris

 

 

 

Frank_Hartmann
Master II
Master II

if you want to do it with a do while clause then also try this:

 

 

LET a=year(today())-5;
if num(month(Today()))=1 and num(day(today()))=1 then
do while a<=year(today())-1;

TEST:
Load
*,FileName() as Filename
From
[C:\Users\admin\Desktop\Neuer Ordner (5)\Test_$(a).xlsx]
(ooxml, embedded labels, table is Tabelle1);
Let a=$(a)+1;
loop;

ELSE

do while a<=year(today());
TEST:
Load
*,FileName() as Filename
From
[C:\Users\admin\Desktop\Neuer Ordner (5)\Test_$(a).xlsx]
(ooxml, embedded labels, table is Tabelle1);
Let a=$(a)+1;
Loop
ENDIF;