Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Date Comparisons

I have the code below where I'm comparing 2 dates to exit the loop.  The loop does not exit, even if the vTmpDate becomes > vMaxDate.  What is the correct way of performing date comparisons?   Thanks in advance!

~ ~ ~ ~ ~

let vMinDate = MakeDate(2013,06,30);

let vMaxDate = MakeDate(2014,04,30);

let vTmpDate = vMinDate;

let i = 0;

DO WHILE Date#('$(vTmpDate)') <= Date#('$(vMaxDate)')

let i = i + 1;
let vTmpDate = MonthEnd('$(vMinDate)',i);
TRACE '$(vTmpDate)';

LOOP

1 Solution

Accepted Solutions
Not applicable
Author

I was able to fix the issue by using the actual variables instead of doing a Dollar Sign Expansion $(...) in the loop condition:

DO WHILE vTmpDate <= vMaxDate

But now I'm confused as when to use DSE versus when to use the actual variables.  I've read that it is a best practice to always use DSE.  Can someone shed some light on this?

View solution in original post

3 Replies
Not applicable
Author

I was able to fix the issue by using the actual variables instead of doing a Dollar Sign Expansion $(...) in the loop condition:

DO WHILE vTmpDate <= vMaxDate

But now I'm confused as when to use DSE versus when to use the actual variables.  I've read that it is a best practice to always use DSE.  Can someone shed some light on this?

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

You have found the right solution. Your problem was due to the specifics of the DO statement. From the Help doc:

"Each condition is interpreted only the first time it is encountered but is evaluated for every time it encountered in the loop"

DSE is interpretation, and interpretation happens only once in DO. At start of the DO, "Date#('$(vTmpDate)')" was getting interpreted to

"Date#('6/30/2013')".

On each interation of the loop, that was getting evaluated, but $(vTmpDate) was not getting interpreted again. Therefore the evaluation was always using "Date#('6/30/2013')".

Here's a good post by HIC on the subject of DSE.

http://community.qlik.com/blogs/qlikviewdesignblog/2013/11/18/dollar-expansions

-Rob

http://masterssummit.com

http://robwunderlich.com

Not applicable
Author

Thanks Rob Wunderlich for the clear explanation and supporting links.  Very much appreciated.