how to get cumulative sum from previous values in the same column

jack10063

Board Regular
Joined
Aug 12, 2008
Messages
103
Hi,

I am trying to create a calculated column that calculates cumulative sum from previous values in the same column. On a spreadsheet I can do it pretty easily as below:


value_date portfolio_number first_value diff_to_target nominal_new
1.11.2015 4 TRUE 10 10
2.11.2015 4 FALSE 15 5
3.11.2015 4 FALSE 20 5
4.11.2015 4 FALSE 25 5
5.11.2015 4 FALSE 30 5
6.11.2015 4 FALSE 35 5
7.11.2015 4 FALSE 40 5
8.11.2015 4 FALSE 45 5
9.11.2015 4 FALSE 50 5

and the formula on spreadsheet is:
Code:
=IF(C4=TRUE;D4;D4-SUMIF($B$2:B3;B4;$E$2:E3))CODE]


So, I would like get nominal_new as calculated column in PowerPivot. For that I need to look diff_to_target at current row and then deduct sum of nominal_new from previous rows in nominal_new column. So, for example for value_date 3.11.2015 nominal new would be 20 (diff_to_target) - 15 (nominal_new 1.11.2015=10+nominal_new 2.11.2015=5) = 5.

For that I tried to create a formula: [CODE]=[diff_to_target]-CALCULATE(SUM(data[nominal_new]);FILTER(ALLEXCEPT(data;data[portfolio_number]);data[value_date]<EARLIER(data[value_date])))

However, PowerPivot doesn't accept that formula because of circular dependency. I was thinking this should be an easy one to build but cant' figure it out. Thanks for any help!

br,
Jack
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
For some reason the DAX formula isn't complete in the previous post. It is continuing as: "EARLIER(data[value_date])))" and "<" before EARLIER but for some reason I can't post it here correctly! :)
 
Last edited:
Upvote 0
Hi Jack,

As you've observed, a calculated column can't refer to itself.

You could avoid circularity by defining [nominal_new] = [diff_to_target] current row - [diff_to_target] previous row.

There are a few ways to do this but here is one possibility:
Code:
=
data[diff_to_target]
    - CALCULATE (
        MAX (data[diff_to_target] ),
        CALCULATETABLE (
            LASTDATE ( data[value_date] ),
            FILTER ( data, data[value_date] < EARLIER ( data[value_date] ) )
        ),
        ALLEXCEPT ( data, data[portfolio_number])
)

(This assumes value_date is data type Date.)

Does this give the right result?
 
Upvote 0

Forum statistics

Threads
1,224,138
Messages
6,176,593
Members
452,738
Latest member
kylua

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top