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: 
Not applicable

load files with year in name

Hi All,

I need to load a files like this:

A:

col1

col2

[col3 2012] as col3

[col4 2012] as col4

FROM table 2012;

B:

col1

col2

[col3 2013] as col3

[col4 2013] as col4

FROM table 2013;

....

I want to avoid manual adding script every year so wanted to use loop with a variable. I know how to run the loop, however i cant manage to load the two fields (col 3 and 4) as variables... Could you please suggest how to do that?

Many thanks

J.

1 Solution

Accepted Solutions
sparur
Specialist II
Specialist II

Hi,

I think this loop could help:


for i = 2012 TO 2013

LET vField1 = 'col3 ' & '$(i)';

LET vField2 = 'col4 ' & '$(i)';

LET vQVDName = 'Table ' & '$(i)';

LOAD

     col1,

     col2,

     [$(vField1)] as col3,

     [$(vField2)] as col4

FROM [$(vQVDName).qvd]

NEXT

View solution in original post

4 Replies
marcus_sommer

You could use the columns position:

@3 as col3

- Marcus

Not applicable
Author

That could help, but i am loading a qvd... so no chance for no labels.

Any other idea?

J.

sparur
Specialist II
Specialist II

Hi,

I think this loop could help:


for i = 2012 TO 2013

LET vField1 = 'col3 ' & '$(i)';

LET vField2 = 'col4 ' & '$(i)';

LET vQVDName = 'Table ' & '$(i)';

LOAD

     col1,

     col2,

     [$(vField1)] as col3,

     [$(vField2)] as col4

FROM [$(vQVDName).qvd]

NEXT

Not applicable
Author

Perfect. It works.

Thanks Anatoly.

J.