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

Rolled Sum

Hi All,

I have some data from Jan 2007 to Dec 2009. I need to display a chart/straight table where the dimension will be the month and expression will be the year 2008 and 2009.

For year 2008 Jan month, I need the sum of Feb 2007 to Jan 2008 and for feb month in 2008, I need the sum of Mar 2007 to Feb 2008 and so on.

I tried the below code but I am not getting the correct sum. Find the data below

sum({<Period=, Months={"$(='<='&Only(Months)&'>'&Only(addmonths(Months,-12)))"} >} Amount )

data

MonthsAmount
Jan-077276
Feb-079071
Mar-077888
Apr-078583
May-077721
Jun-077876
Jul-077526
Aug-078049.1
Sep-077763
Oct-078064
Nov-079150
Dec-079144
Jan-0811195
Feb-089858
Mar-0810801
Apr-089895
May-0810796
Jun-0811864
Jul-088902
Aug-089130
Sep-089483
Oct-089020
Nov-089569
Dec-0810792
Jan-094317
Feb-098504
Mar-098381
Apr-0910101
May-099325
Jun-0913515
Jul-098675
Aug-098803
Sep-097048
Oct-098691
Nov-099159
Dec-099673


Hope someone can help me

Best Regards,

Sajeevan



4 Replies
Not applicable
Author

You could try to run a sum for all year minus sum for the month N-1 ?

using set analysis ?

Not applicable
Author

Hi,

Can you share how the code will be?

Thanks,

Sajeevan

Anonymous
Not applicable
Author

Hi Sajeevan,

First you need to make sure that the Months field is in a proper date format. I added a preceding load to your table in the script:

Data:
Load
date(date#(Months,'MMM-YY'),'MMM-YY') as Months,
Amount;
LOAD * INLINE [
Months, Amount
Jan-07, 7276
Feb-07, 9071
Mar-07, 7888
Apr-07, 8583

etc.

Then you should be able to use an expression like this:

sum({<Period=, Months={"$(='<='&Only(Months) & '>' & only(date(addmonths(Months,-12),'MMM-YY')))"} >} Amount )

Notice that I've added another date() around the addmonths() function. This is because the addmonths() function will format the date value as a full date with days included and we want to strip it down to MMM-YY.

Not applicable
Author

Hi Johannes,

Thanks for your response. I have the proper date format in Months field. I am not getting the desired result with this expression even after adding the date formating while loading and in the expression. Ideally the rolled sum should have been 102,030 for the month Jan in year 2008 (Feb-07 to Jan-08) but I am getting 22,788.

I think this expression will work only if I select a month otherwise it shows Months={"<=>"}. I am not providing a month selection for the user. If I select the month as Jan-08 then the expression shows Months={"<=Jan-08>Feb-07"} and the rolled sum is only for Jan-08

What I wanted in my chart is

- the dimention month(Months)

- expression for year 2008

- expression for year 2009

I don't know how to attach my QVW file in this mail. I have both versions 8.5 and 9.0