Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
baarathi
Creator III
Creator III

Do While in Qlik Sense to repeat a set of statements

I'm using do while loop and using variable as do while condition. Where the variable used after do while condition is not treated as variable.tempsnip909.png

Labels (3)
3 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

The expression in vDD can only be evaluated in the front end. To get the Max, you will need to load it into a temp table with a line like "Max(...) as maxval". Then you can peek the value of maxval into vDD. Check Peek() in the online help.

Also the let statements in the loop won't work as you are just setting them to strings. Use

Let vStart = vStart + 30;
Let vEnd = vEnd + 30;

etc

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
baarathi
Creator III
Creator III
Author

@jonathandienst  Thank You. As you said Let vDD = Peek('DifferenceofDates',0,Test1); The peek function works fine.

But the loop gets executed indefinitely

Do While '$(vDD)' > 0

Test:
LOAD
Distinct StartDate,
TransactionDate,
CorporateName,
Entry,
CountOfID,
DifferenceofDates,
If(DifferenceofDates >= '$(vStart)' and DifferenceofDates < '$(vEnd)', 'M' & '$(vNum)','Null') as MonthDiff
FROM [lib://QVDs/SampOn.xlsx]
(ooxml, embedded labels, table is Sheet1);
Let vStart = '$(vStart)' + 30;
Let vEnd = '$(vEnd)' + 30;
Let vDD = '$(vDD)' - 1;
Let vNum = '$(vNum)' + 1;
Loop

jonathandienst
Partner - Champion III
Partner - Champion III

You don't need $ expansions and putting quotes around tells Qlik to treat them as strings.So

Let vDD = Peek('...);
Let vStart = 1;
Let vEnd = 31;
Let vNum = 1;

Do While vDD > 0
	Test:
	LOAD
		Distinct StartDate,
		TransactionDate,
		CorporateName,
		Entry,
		CountOfID,
		DifferenceofDates,
		If(DifferenceofDates >= $(vStart) and DifferenceofDates < $(vEnd), 'M' & '$(vNum)','Null') as MonthDiff
	FROM [lib://QVDs/SampOn.xlsx]
	(ooxml, embedded labels, table is Sheet1);
	
	Let vStart = vStart + 30;
	Let vEnd = vEnd + 30;
	Let vDD = vDD - 1;
	Let vNum = vNum + 1;
Loop
Logic will get you from a to b. Imagination will take you everywhere. - A Einstein