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: 
J_Post
Contributor II
Contributor II

RangeSum to get rolling sum value

I am trying to get a rolling value for each client. My data is set up as follows:

Table1:
Load *
Inline [
Client, Month, Value
AAA, 1, 300
AAA, 2, 550
AAA, 3, 600
BBB, 1, 250
BBB, 2, 475
];

 

I am trying to calculate the total value up to and including the current month for each client in the load script. The end result should be something like this.

J_Post_0-1699280284118.png

How can I achieve this in the load script. I have tried RangeSum functions, but can't seem to get them to work. 

Labels (2)
1 Solution

Accepted Solutions
MeehyeOh
Partner - Creator
Partner - Creator

Hi, @J_Post 

Try this.

-Script 

TMP:
Load * 
Inline [
Client, Month, Value
AAA, 1, 300
AAA, 2, 550
AAA, 3, 600
BBB, 1, 250
BBB, 2, 475
];
 
Table:
Load
*,
    If(Client=Peek(Client), Peek(ROLLING_Value)+Value,Value) As ROLLING_Value
Resident TMP
Order By Client,Month;
Drop table TMP;

 

-Result

MeehyeOh_0-1699316012670.png

 

Reply~! thanks!

View solution in original post

3 Replies
Or
MVP
MVP

https://community.qlik.com/t5/New-to-Qlik-Sense/Cumulative-Sum-in-Script-Qlik-Sense/td-p/1612574

That said, it's often better to do it on the front end so it can react to selections...

https://community.qlik.com/t5/New-to-Qlik-Sense/Running-total-per-dimension/td-p/1542119

There should be more than a few other threads with solutions for this sort of issue if you'd like to search for more.

Gabbar
Specialist
Specialist

Add this in your script :-

noconcatenate
Load *, If(Client =previous(Client),Value+peek(Rolling_Sum),Value) as Rolling_Sum resident Table1
order by Client ASC, Month ASC.

I hope your month is in numerical format , if not change it into numerical format of YYYYMM for sorting.

Also, what @Or said, better to do it in UI. using RangeSum and above.

MeehyeOh
Partner - Creator
Partner - Creator

Hi, @J_Post 

Try this.

-Script 

TMP:
Load * 
Inline [
Client, Month, Value
AAA, 1, 300
AAA, 2, 550
AAA, 3, 600
BBB, 1, 250
BBB, 2, 475
];
 
Table:
Load
*,
    If(Client=Peek(Client), Peek(ROLLING_Value)+Value,Value) As ROLLING_Value
Resident TMP
Order By Client,Month;
Drop table TMP;

 

-Result

MeehyeOh_0-1699316012670.png

 

Reply~! thanks!