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

For ... each in filelist

Hello,

very simple and stupid problem, but I'm not able to find a solution. This is my script:

FOR EACH FILE IN FileList('$(DIRBUDGET)budget_201*.xls')

load .......

FROM

$(FILE)

(biff, embedded labels, header is 1 lines, table is Operatori$);

next FILE;

It load all my files from 2010 to 2019... but I need 2009, too, and I don't want to load 2008 and 2007. And cause I'm working on someone else script, I wouldn't want to change the structure of the script. I simply want to add 2009 file.

Thanks

Filippo

1 Solution

Accepted Solutions
Not applicable
Author

Unfortunately variable FILE is used lots of times. And this loop is used several times. I don't want to create a new loop. I could instead add a second loop, maybe using year variable. What could be the right syntax?

for year = 2009 to 2014

FOR EACH FILE IN FileList('$(DIRBUDGET)budget_$(year).xls')

load ...

next file

next year

Is it correct?

View solution in original post

8 Replies
christophebrault
Specialist
Specialist

Why don't you just load 2009 in another part of script just before or after ?

Dont't use the loop, just :

load .......

FROM

budget_2009.xls // your path to 2009

(biff, embedded labels, header is 1 lines, table is Operatori$);

When you load exactly the same fields and tables will concatenate.

Hope this can solve easily your problem.

Inscrivez vous à ma Newletter Qlik
DoNotMissQlik- Connect with me on Linkedin
Not applicable
Author

Cause if tomorrow  someone wants  to see 2008 and 2009 sales I have to add a part of script newly. It works but it's not so "lean".

ekech_infomotio
Partner - Creator II
Partner - Creator II

Hi Filippo,

you could use

the following:

set vBaseDir = '\\path\to\your\files\';

set vBaseName = 'budget_';

for each vMonth in '2009', '2010', '2011', ...,  '2019'

     load

          *

     from

          $(vBaseDir)$(vBaseName)$(vMonth).xls (biff, embedded labels, header is 1 lines, table is Operatori$);

next vMonth

;

So you can load other months in a very simple way by adding/deleting values to your list

regards,

Edgar



CELAMBARASAN
Partner - Champion
Partner - Champion

Hi,

You can try with this

For year=2009 to 2019

load .......

FROM

$(DIRBUDGET)budget_$(year).xls

(biff, embedded labels, header is 1 lines, table is Operatori$);

next;

Hope it helps

Celambarasan

Not applicable
Author

Unfortunately variable FILE is used lots of times. And this loop is used several times. I don't want to create a new loop. I could instead add a second loop, maybe using year variable. What could be the right syntax?

for year = 2009 to 2014

FOR EACH FILE IN FileList('$(DIRBUDGET)budget_$(year).xls')

load ...

next file

next year

Is it correct?

SunilChauhan
Champion II
Champion II

use below code

FOR EACH FILE IN FileList('$(DIRBUDGET)budget_201*.xls','$(DIRBUDGET)budget_2009*.xls')

load .......

FROM

$(FILE)

(biff, embedded labels, header is 1 lines, table is Operatori$);

next FILE;

hope this helps

Sunil Chauhan
Not applicable
Author

I modified it and now it works as I want.

Thanks you all...

Not applicable
Author

use below code

FOR EACH FILE IN FileList('$(DIRBUDGET)budget_201*.xls','$(DIRBUDGET)budget_2009*.xls')

load .......

FROM

$(FILE)

(biff, embedded labels, header is 1 lines, table is Operatori$);

next FILE;

hope this helps

Hi Sunil,

this was my first attempt, but it doesn't worked.