Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
srihitha
Contributor III

do loop not working as expected

I am new to qlik sense and i am trying to use below do loop to create a simple table. But table is not getting created although code is running successfully. Can someone please explain why table is not getting created.

table:
let a=1;

do while (a<=5)

load a;
a=a+1;
loop;

 

 

Labels (2)
1 Solution

Accepted Solutions
vinieme12
Champion III

As below, the table creation must be within the loop, not outside the loop

1) Using Do While

let a=1;
Do while a<10
Table:
LOAD $(a) as field
AutoGenerate 1;
Let a=a+1;
Loop

 

 

1) Using only start and end variables

LET vstart = 1;
LET vend = 10;
Table:
lOAD $(vstart)+ITERNO()-1 as field
AutoGenerate 1
WHILE $(vstart)+ITERNO()-1 <= $(vend);

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.

View solution in original post

2 Replies
vinieme12
Champion III

As below, the table creation must be within the loop, not outside the loop

1) Using Do While

let a=1;
Do while a<10
Table:
LOAD $(a) as field
AutoGenerate 1;
Let a=a+1;
Loop

 

 

1) Using only start and end variables

LET vstart = 1;
LET vend = 10;
Table:
lOAD $(vstart)+ITERNO()-1 as field
AutoGenerate 1
WHILE $(vstart)+ITERNO()-1 <= $(vend);

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
srihitha
Contributor III
Author

Hi Vineeth,

Thanks for your reply and your solution is working fine

Table creation outside the loop is also working fine. Does placement of tablename: really make difference?

Table1:
let a=1;
Do while a<10

LOAD $(a) as field
AutoGenerate 1;
Let a=a+1;
Loop