Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
vikasshana
Creator II
Creator II

Need Expression to calculate previous YTD Sales

Hi Everyone,

I have the below sample data which has the previous year and current year sales.

Order DateSales
                                                                                             22-08-2018                                                                                                           13.7
 22-08-201931.5
04-05-2020243.16
04-07-202025.248
22-07-2020258.576
04-08-2020243.16
22-08-202029.6

 

I use the below code to get current YTD Sales and is working and i'm getting sales of '799.744'

 

vCurrentYear: =Max(Year([Order Date]))

=sum({<Year={$(vCurrentYear)}>}Sales)

 

Now I'm looking for previous year to date  expression, i tried using the below expression but it is giving output as '31.5' but it has to be '831.244 (799.744 + 31.5)'

 

vPreviousYear: =Max(Year([Order Date])-1)

=sum({<Year={$(vPreviousYear)}>}Sales)

 

Regards,

Bharath Vikas

Labels (1)
2 Replies
sunny_talwar

Previous year is 2019, do you not want 2019 for previous year? You want 2020 + 2019 for previous year?

Kushal_Chawda

If you just want previous year then your logic is correct. Probably what you want is not previous year sales then. It's yearly cumulative sales. Where you want to show this value in chart or text object?