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: 
Peony
Creator III
Creator III

Several variable in "for each ... next" loop

Hi there!
I have a code example below that in each iteration brings me value for id. The thing is that I need to receive value for sub_id( that relevant to the id) in the same time.

If this could be possible, I would describe loop like   For Each id in $(id_list) and sub_ id in $(sub_id_list). But this option doesn't exists. So maybe someone have an idea how to bring  values for sub_id into this loop. Or create some other loop maybe. 

The end result of each iteration is a url string where id and sub_id are parts of it:  URL"https://somessite.com/servlet/ExportToXML/export?import=1&section_id=$(id)&plain=1&selected_id=$... 

tmp:
Load * Inline [
	id, sub_id
	1, 	101
	2, 	202
	3, 	303
];

test:
Load 
	concat(id , ',') 		as id_concat,
	concat(sub_id , ',') 	as sub_id_concat
Resident 
	tmp;

Drop Table tmp;

Let id_list		= peek ('id_concat',	 0,'test' );
Let sub_id_list	= peek ('sub_id_concat', 0,'test' );

For Each id in $(id_list)

	Trace id $(id);

Next id

 

Labels (3)
1 Solution

Accepted Solutions
Peony
Creator III
Creator III
Author

I already found solution by myself. I just chose wrong type pf loop. In the example below everything works fine for me.

tmp:
Load * Inline [
	id, sub_id
	1, 	101
	2, 	202
	3, 	303
];

count_tmp:
Load 
	Count (id) as count_id
Resident 
	tmp;
	
Let vCount_id = Peek('count_id', 0, 'count_tmp');

For i = 0 to $(vCount_id)-1

	Let vID 		= Peek('id', 	 $(i), 'tmp');
	Let vSub_ID 	= Peek('sub_id', $(i), 'tmp');
	
	trace vID $(vID) and vSub_ID $(vSub_ID);

Next i;

Drop table tmp;

View solution in original post

1 Reply
Peony
Creator III
Creator III
Author

I already found solution by myself. I just chose wrong type pf loop. In the example below everything works fine for me.

tmp:
Load * Inline [
	id, sub_id
	1, 	101
	2, 	202
	3, 	303
];

count_tmp:
Load 
	Count (id) as count_id
Resident 
	tmp;
	
Let vCount_id = Peek('count_id', 0, 'count_tmp');

For i = 0 to $(vCount_id)-1

	Let vID 		= Peek('id', 	 $(i), 'tmp');
	Let vSub_ID 	= Peek('sub_id', $(i), 'tmp');
	
	trace vID $(vID) and vSub_ID $(vSub_ID);

Next i;

Drop table tmp;