Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
salleninsd
Creator
Creator

Syntax for replacing current year with prior year date in expression

Hello,

I have a variable set up $(vUserInputStartDate) which returns a start date (i.e. 2019-01-01).  When I put it in an expression, I want to convert the 2019-01-01 to 2018-01-01, but I'm having trouble with the syntax to convert it (basically, change the year to previous year.

Any suggestions are much appreciated!  Thank you.

Date Expression.JPG

1 Solution

Accepted Solutions
NZFei
Partner - Specialist
Partner - Specialist

Replace >=$(vUserInputStart) with >=$(=addyears(vUserInputStart,-1))

View solution in original post

3 Replies
salleninsd
Creator
Creator
Author

By the way, the default for my vUserInputStartDate variable is:

=date(max([MasterCalendar.FirstDayOfMonth],13), 'YYYY-MM-DD')

Date Expression 2.JPG

NZFei
Partner - Specialist
Partner - Specialist

Replace >=$(vUserInputStart) with >=$(=addyears(vUserInputStart,-1))

salleninsd
Creator
Creator
Author

Woo Hoo, thanks Xufei123!  I was struggling with trying to put it into the same YYYY-MM-DD format, and it was getting jacked up.  Your syntax works.

This is what I had, and it wasn't working:

sum({$<[DimDateSOC.FullDate]={">=$(=addyears(vUserInputStart,-1),'YYYY-MM-DD') <=$(=addyears(vUserInputEnd,-1),'YYYY-MM-DD')"}>}[Episode.IsAdmit])

Take good care, and thanks again!

Scott