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: 
Not applicable

Calculate sales for previous year

Hi!

I wan't to use year as dimension and calculate the sales for the previous year. How do I do this if I wan't to view 4 years at the same time? Like this:

YearSales
2014Sales for 2013
2013Sales for 2012
2012Sales for 2011
2011Sales for 2010

How do I do this in the easiest way?

Thanks in advance!

9 Replies
alexandros17
Partner - Champion III
Partner - Champion III

If you have a date for sales for example sale_date then when you load your sales data add a field year(sale_date) as year, in this way simply doing a sum of sales values in the expression (using year as dimension) you will have whqat you need

Let me know

its_anandrjs

Its seems like rolling 4 years from current year. Work on the rolling years.

maleksafa
Specialist
Specialist

you have many ways to achieve that depending on your data model, you can prepare the previous sales in the script using the peek function on each year to peek the sales of the previous year.

you can do that from the chart using set analysis, where you will define a variable called vPreviousYear which is the selected year - 1 and use it when calculating the sales of this year, or if the years are sorted you can use the below function to get the sales of the below row for example the below sales for year 2014 will return the sales of 2013.

PradeepReddy
Specialist II
Specialist II

If you want to showcase the data in table format , see the attachment.

its_anandrjs

Hi Kim,

Easiest way of solve this problem would be i explain with an example see the inline table here i take 7 years sales data

and in the front end i take the straight table

LOAD * INLINE [

    Year, Sales

    2014, 43432

    2013, 43244

    2012, 34556

    2011, 54545

    2010, 45365

    2009, 45356

    2008, 45653

];

1.Straight table with dimension and expression

Dimension:- Year+1

Expression:- sum({<Year= { '>=$(=max(Year)-4)  <=$(=max(Year)-1) '}>} Sales)

Note:- As you describe you need the data as and this chart is dynamic when you select 2012 year this will gives last 4 years data.

YearSales
2014Sales for 2013
2013Sales for 2012
2012Sales for 2011
2011Sales for 2010

And then in the straight table you get data as mention above

Roll4years.png

Regards

Not applicable
Author

Thanks for your reply.

I tried using the above-funktion but it returns null for the first year, which is correct but I wan't to hide this row, is that possible?

asdf.PNG.png

alexandros17
Partner - Champion III
Partner - Champion III

Check (in the presentation tab) the box "suppress zero values"

Not applicable
Author

Tried that, didn't help I'm afraid.

alexandros17
Partner - Champion III
Partner - Champion III

Could you attach your document?