Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Conditional Variable Expansion in Loop?

I am trying to have some values read as literals while others should be replace by the variable value.

Example Input file:


 

So when I do this the first four ID’s come as I want which is literal. However I want the fifth one to show as ‘111’,’222’,’333’

 

Variable Output I Get

 

v_ID1 = ‘111’

v_ID2 = ‘222’

v_ID3= ‘333’

v_ID4= ‘444’

v_ID5= $(v_ID1),$(v_ID2),$(v_ID3)

My script is like this:

Test:
LOAD
Type,
Variable,
$(vVariableValue)  //NOTE I do have this variabalized but for the input file examples sake I kept just to loading from one example to keep it simpler

FROM

'..\includes\File1.xlsx'
(
ooxml, embedded labels, table is Sheet1) ;


LET vNumberofRows = NoOfRows ('Test');
For vI = 0 to (vNumberofRows - 1);

LET vVariable= Peek('Variable',vI,'Test');
LET vValue= Peek ('$(vVariableValue)',vI,'Test');
LET [$(vVariable)] = Peek ('$(vVariableValue)', vI, 'Test') ;

Next;

Do I Need to do some sort of IF logic inside of the loop to treat these differently?

I just can’t seem to get the syntax to work

 

Also note, I am trying to do this without minimal changing of the source excel file format.

1 Reply
settu_periasamy
Master III
Master III

Hi,

Are you ok to give the input for v_ID5 like below

TypeVariableVariableValue
Singlev_ID1'111'
Singlev_ID2'222'
Singlev_ID3'333'
Singlev_ID4'444'
Multiplev_ID5=v_ID1&','&v_ID2&','&v_ID3

you will get

Capture.JPG

And, i did small change in your script. Check the Attachment