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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Set Analysis with Dates - Previous Months based on current date

I'm trying to get results based on a current date (YTD, most recent full Month/Quarter etc.) using the following...

Set vCurrentDate= Date('22/02/2015', 'DD/MM/YYYY')  // This would not be hard coded but as this is an example it serves the purpose.

With the following Set Analysis equation I get the desired result

='Current Month when date Hard Coded : ' & MaxString({< Date={'22/02/2015'} >} Date) // Returns 22/02/2015

But this just returns the maximum result stored in the calendar.

='Current Date using vCurrentDate : ' & MaxString({ <Date={"=$(vCurrentDate)"}> } Date)

I've tried various formats and achieved nothing. i.e. Date={'$(vCurrentDate)'} etc.

See attached App for issues and CSV used for Dates

12 Replies
rubenmarin

Hi Colin, transforming each expression:

='vCurrentDate : ' & $(vCurrentDate) is transformed as ='vCurrentDate : ' & 22/02/2015 <-- This is a division: 22 / 2 = 11 / 2015 = 0.00549...
Following operators priority division and multiplication are executed before addition and substration, and the '&' used for concatenate strings is treated as an 'addition' of strings, so first it does the division and then the contenation of the result as a string

='vCurrentDate : ' & '$(vCurrentDate)' is transformed as ='vCurrentDate : ' & '22/02/2015' <-- This is a concatenation of two strings


='vCurrentDate : ' & Num('$(vCurrentDate)') is transformed as ='vCurrentDate : ' & Num('22/02/2015') <-- QV is smart enough to interpret the string as a date and returns it's numerical value of 42057



rubenmarin

Just one detail, for other users loking for the same question, the answer you marked as correct is the one I pasted wrong.

Not applicable
Author

Updated, thanks again!

If it looks like a duck....