Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
BHoll
Contributor III
Contributor III

For Loop with two variables

Hello Everyone,

i'm trying to figure out, how to code a for loop in Qlikview that is iterating throught two variables at the same time (no nested for Loop)

 

I imagine the code to work like this:

for each vNumber,vLetter in ((1,2,3,4),(A,B,C,D))

trace$(vNumber);

trace$(vLetter);

Next;

 

Desired Output would be:

1

A

2

B

3

C

4

D

 

best regards,

smbeholl

1 Solution

Accepted Solutions
Vegar
MVP
MVP

If you are able to combine the two into one value using | as separator then
you could do this.

FOR EACH vLetterNumber IN 'A|1', 'B|2', 'C|3','D|4'
LET vNumber=subfield('$(vLetterNumber)','|',2);
trace $(vNumber);
LET vLetter=subfield('$(vLetterNumber)','|',1);

trace $(vLetter);
Next


View solution in original post

6 Replies
sunny_talwar

Will you always have the same number of items in vNumber and vLetter? and how are they two linked together? the order of their listing?

Vegar
MVP
MVP

You would need to create two loops to accomplish this. One per variable.

for each vNumber in 1,2,3,4
for each vLetter in 'A', 'B', 'C','D'
trace$(vNumber);
trace$(vLetter);
Next;
Next

BHoll
Contributor III
Contributor III
Author

I'll always have the same number of items in vNumber and vLetter. Not sure if i'm getting the second part of you question right, but like in my opening post, both variables should take the first value of their list first, then the second and so on.

thanks for your help!

BHoll
Contributor III
Contributor III
Author


@Vegar wrote:
You would need to create two loops to accomplish this. One per variable.

for each vNumber in 1,2,3,4
for each vLetter in 'A', 'B', 'C','D'
trace$(vNumber);
trace$(vLetter);
Next;
Next


This is a nested for loop and will give me the following output:

1

A

1

B

1

C

1

D

2

A

2

B

2

C

2

D

....

....

Vegar
MVP
MVP

If you are able to combine the two into one value using | as separator then
you could do this.

FOR EACH vLetterNumber IN 'A|1', 'B|2', 'C|3','D|4'
LET vNumber=subfield('$(vLetterNumber)','|',2);
trace $(vNumber);
LET vLetter=subfield('$(vLetterNumber)','|',1);

trace $(vLetter);
Next


BHoll
Contributor III
Contributor III
Author

Thanks, this is definetly a good work around!