Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content
Announcements
Qlik Connect 2025! Where innovative solutions turn your data visions into reality: REGISTER TODAY
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Having Problem inserting a Variable in a loop

Hi

I´m having trouble inserting a variable into a loop. When I have only the first segment I get no data, it makes no itineration. When I have the data from the second segment I get all the data.

In the next lines on the first segment the loop, on the second segment the code for the loop expanded.

I think the problem is in the this part do while vTotalCount=0 but not sure how to change the syntax

First Segment

do while vTotalCount=0

call Registros($(vTimeStamp))

Let vTimeStamp = Peek('TimeStamp',-1,'Clients');
Let vTotalCount = Peek('TotalCount',-1,'MetaCollectionResult');

loop

Second Segment

// call Registros($(vTimeStamp))
// Let vTimeStamp = Peek('TimeStamp',-1,'Clients');
// Let vTotalCount = Peek('TotalCount',-1,'MetaCollectionResult');

// call Registros($(vTimeStamp))
// Let vTimeStamp = Peek('TimeStamp',-1,'Clients');
// Let vTotalCount = Peek('TotalCount',-1,'MetaCollectionResult');

// call Registros($(vTimeStamp))
// Let vTimeStamp = Peek('TimeStamp',-1,'Clients');
// Let vTotalCount = Peek('TotalCount',-1,'MetaCollectionResult');

 

Labels (1)
1 Solution

Accepted Solutions
Vegar
MVP
MVP

You could try to change from a While statement to an Until  statement un your loop. Take a look at the help page  Do..loop .

do until  vTotalCount=0

loop

Or you can change the condition

do while  vTotalCount <> 0

loop

View solution in original post

6 Replies
Vegar
MVP
MVP

What if you declare the variable in prior to the loop? Like this.

Set vTotalCount=0;

do while vTotalCount=0

call Registros($(vTimeStamp))

Let vTimeStamp = Peek('TimeStamp',-1,'Clients');
Let vTotalCount = Peek('TotalCount',-1,'MetaCollectionResult');

loop

Anonymous
Not applicable
Author

Vegar hi

I tried but it only makes the first loop although when it finish,  the variable vTotalCount is equal to 117 and stops....

 

Vegar
MVP
MVP

I don't follow. 

If vTotalCount is equal to 117, then the loop should stop.  You o not want to loop if it is equal to zero or do I misunderstand your concern? 

Anonymous
Not applicable
Author

Vegar hi

I want the loop to go until the variable is equal to 0.

The variable values are: 117, 60, 17 and 0

Should I change the condition?

Vegar
MVP
MVP

You could try to change from a While statement to an Until  statement un your loop. Take a look at the help page  Do..loop .

do until  vTotalCount=0

loop

Or you can change the condition

do while  vTotalCount <> 0

loop

Anonymous
Not applicable
Author

Vegar hi

 

Thank you for your help