Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
AmCh
Creator
Creator

LOAD within for loop

Hello all,

I have, for example, an xls. file with several sheets.

Each sheet contains the same tables structure (same number of columns and rows, they only differ in the cell values).

The sheets are named as follows: L_A, L_B, L_C

The fields have identical names in all sheets: x,y,z

 

Objective:

To load with for loop (incrementing in the list {A,B,C}) from the sheets (L_A, L_B, L_C) the fields (x,y,z) as (x_A,x_B,x_C,Y_A,..).

 

Can anyone help me?

 

Many thanks in advance

Labels (3)
1 Solution

Accepted Solutions
edwin
Master II
Master II

you can do however you want it, in you load statement, you can specify NOCONCATENATE and  you can embed your sheetname into the field names, you can even use the variable in the tablename 

 

for Each vSheet in 'A','B','C'
NoConcatenate
Sheet$(vSheet):
LOAD x as x$(vSheet), 
     y as y$(vSheet), 
     z as z$(vSheet)
FROM
[file.xlsx]
(ooxml, embedded labels, table is $(vSheet));
next;

 

 

edwin_0-1611517750329.png

 

View solution in original post

4 Replies
edwin
Master II
Master II

AmCh
Creator
Creator
Author

My imported fields should be imported separtely and not concatenated in one field ( e.g. Field a from Sheet 1 and field a from Sheet 2 should be imported as a1 from Sheet 1 and as a2 from Sheet 2). 

(In my case not numerical index but the index should be taken from a list of names)

edwin
Master II
Master II

you can do however you want it, in you load statement, you can specify NOCONCATENATE and  you can embed your sheetname into the field names, you can even use the variable in the tablename 

 

for Each vSheet in 'A','B','C'
NoConcatenate
Sheet$(vSheet):
LOAD x as x$(vSheet), 
     y as y$(vSheet), 
     z as z$(vSheet)
FROM
[file.xlsx]
(ooxml, embedded labels, table is $(vSheet));
next;

 

 

edwin_0-1611517750329.png

 

edwin
Master II
Master II

obviously, if your sheet is L_A, L_B, etc..

use A, B, C as the variable value and just add L_ in the sheet name 
... table is L_$(vSheet)
itll be easier