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

Announcements
Posting on Qlik Community is temporarily paused for some users. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
Ken_Hardwick
Contributor III
Contributor III

Prior year sales not calculating

Hello,

I am trying to do a KPI chart that compares YTD sales v PYTD sales but I am getting nil for PYTD no matter what I try. What I have at the moment is:

1) A variable - vTodayPriorYear = date(addyears(max(Today()),-1),'DD/MM/YYYY')

2) Expression - SUM({$< Year={'$(vPriorYear)'}, CalDate={'<=$(vTodayPriorYear)'} >} [Gross sales value])

If I remove the bold section of the expression above, I get all the sales for the prior year but once added, I get zero. In the edit expression window I am getting OK & SUM({$< Year={'2018'}, CalDate={'<=17/11/2018'} >} [Gross sales value]) so from that I know the variable is working.

How can I determine where this is falling over?

1 Solution

Accepted Solutions
sunny_talwar
MVP
MVP

If you want to stick with your current approach... can you try this

vTodayPriorYear = Date(AddYears(Today(),-1), 'DD/MM/YYYY')

And then this (added an equal sign after $(...

Sum({$<Year = {'$(vPriorYear)'}, CalDate = {'<$(=vTodayPriorYear)'}>} [Gross sales value])

or this (added an =$( after $(

Sum({$<Year = {'$(vPriorYear)'}, CalDate = {'<$(=$(vTodayPriorYear))'}>} [Gross sales value])

View solution in original post

3 Replies
Kashyap_R
Partner - Specialist
Partner - Specialist

Hi 

Try this

YTD  :  Sum({$<CalDate={">=$(=Date(YearStart(Today()))))<=$(=Today())"}>}[Gross sales value])

PYTD : Sum({$<CalDate={">=$(=Date(AddYear(YearStart(Today())),-1))<=$(=Date(AddYears(Today(),-1)))"}>}[Gross sales                                              value])

 

Hope this helps

Thanks

Thanks and Regards
Kashyap.R
sunny_talwar
MVP
MVP

If you want to stick with your current approach... can you try this

vTodayPriorYear = Date(AddYears(Today(),-1), 'DD/MM/YYYY')

And then this (added an equal sign after $(...

Sum({$<Year = {'$(vPriorYear)'}, CalDate = {'<$(=vTodayPriorYear)'}>} [Gross sales value])

or this (added an =$( after $(

Sum({$<Year = {'$(vPriorYear)'}, CalDate = {'<$(=$(vTodayPriorYear))'}>} [Gross sales value])
Ken_Hardwick
Contributor III
Contributor III
Author

Thanks for both the replies. As I am new and learning, seeing more than one approach helps.