Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Announcements
Save $300 - Register for QlikWorld (formerly Qonnections) by January 31st: Learn More
baarathi
Contributor 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

3 Replies
MVP
MVP

Re: Do While in Qlik Sense to repeat a set of statements

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
Contributor III

Re: Do While in Qlik Sense to repeat a set of statements

@jontydkpi  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

MVP
MVP

Re: Do While in Qlik Sense to repeat a set of statements

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