
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@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


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
