Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
SA_VO
Contributor II
Contributor II

Concatenate string along loop

Hi everyone,

 

I am looking for a solution to concatenate strings from a field as follows:

Say my source data is 

sample_table:
load * inline [
Email | department
abc@test.com | IT
abc@test.com | HR
def@test.com | HR
lmn@test.com | IT ];

I would like to create a loop where for instances of repeat emails I concatenate the string, something like department(iterno()-1 &',' & department(iterno()) so that my end table would look like:

Email | department
abc@test.com | IT, HR
def@test.com | HR
lmn@test.com | IT

 

I am relatively new to working with Qlik Sense, I understand I need to define some variables here but am lost how to do so.

Any help appreciated!

Labels (3)
2 Solutions

Accepted Solutions
marcus_sommer
MVP
MVP

You need no loop else you could aggregate the strings with concat().

- Marcus

View solution in original post

durgesh22
Creator
Creator

Hi @SA_VO 

Please check below ,it might help.

tab1:
load * inline [
Email ,department
abc@test.com , IT
abc@test.com , HR
def@test.com , HR
lmn@test.com , IT
lmn1@test.com , IT
lmn1@test.com , Sales
lmn1@test.com , Marketing] ;

NoConcatenate
tab2:
load Email,Concat(department,',') as department Resident tab1 group by Email;
drop Table tab1;


Exit Script;

 

 

View solution in original post

3 Replies
marcus_sommer
MVP
MVP

You need no loop else you could aggregate the strings with concat().

- Marcus

durgesh22
Creator
Creator

Hi @SA_VO 

Please check below ,it might help.

tab1:
load * inline [
Email ,department
abc@test.com , IT
abc@test.com , HR
def@test.com , HR
lmn@test.com , IT
lmn1@test.com , IT
lmn1@test.com , Sales
lmn1@test.com , Marketing] ;

NoConcatenate
tab2:
load Email,Concat(department,',') as department Resident tab1 group by Email;
drop Table tab1;


Exit Script;

 

 

SA_VO
Contributor II
Contributor II
Author

I understand my mistake, I completely misinterpreted what the concat() function does.

Both solutions are correct, thank you!