Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
sujit_nath
Creator III
Creator III

Help with concatenating values with loop and store in a variable

I need to loop from 1-20 (for example)

and take a variable such that value of the variable would be :   Replace(Replace(Replace(Replace(Replace(.......... 20 times.

Could some one help me with this?

1 Solution

Accepted Solutions
tresesco
MVP
MVP

You could try something like:

load * Inline [

Exclude

D

E

F

];

temp:

Load

  Key,

  Replace(Replace(Replace(If( IterNo()=1, Key,Peek('KeyNew')), FieldValue('Exclude', IterNo()),''), '[',''),']','') as KeyNew

While IterNo()<=FieldValueCount('Exclude');

Load * Inline "

Key

";

FinalExclusion:

Load Key as FinalExclude Resident temp where Len(KeyNew)=0;


NoConcatenate

Final:

Load Distinct Key Resident temp where not Exists(FinalExclude, Key);

Drop Table temp;

View solution in original post

5 Replies
vishsaggi
Champion III
Champion III

Can you share some sample data and what you are expecting to see? Why you need 20 Replace functions? Just wanted to understand?

sujit_nath
Creator III
Creator III
Author

Hi Vishwarath,

This would be in reference to a the ques posted:

How to exclude possible combinations of few keys?

If you see one of the answers there, this approach is suggested. So, wanted to take that with loop rather than manually writing all that.

Anonymous
Not applicable

Hi,

Perhaps use a for loop with a peek function inside the loop

tresesco
MVP
MVP

You could try something like:

load * Inline [

Exclude

D

E

F

];

temp:

Load

  Key,

  Replace(Replace(Replace(If( IterNo()=1, Key,Peek('KeyNew')), FieldValue('Exclude', IterNo()),''), '[',''),']','') as KeyNew

While IterNo()<=FieldValueCount('Exclude');

Load * Inline "

Key

";

FinalExclusion:

Load Key as FinalExclude Resident temp where Len(KeyNew)=0;


NoConcatenate

Final:

Load Distinct Key Resident temp where not Exists(FinalExclude, Key);

Drop Table temp;

sujit_nath
Creator III
Creator III
Author

This is incredible!! That actually works and is a great solution in few LOC's.

Thanks a lot