Sum row on change of account (Excel 365)

henryg

Board Regular
Joined
Oct 23, 2008
Messages
150
Office Version
  1. 365
Platform
  1. Windows
I want to get an accumulating sum of rows in the balance column where, in this case, the account number is the same. For example,

[TABLE="width: 500"]
<tbody>[TR]
[TD]Day[/TD]
[TD]Account[/TD]
[TD]Dr[/TD]
[TD]Cr[/TD]
[TD]Balance[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1000[/TD]
[TD]100[/TD]
[TD]75[/TD]
[TD]? (25)[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1000[/TD]
[TD]500[/TD]
[TD]260[/TD]
[TD]? (265)[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]1150[/TD]
[TD]400[/TD]
[TD]100[/TD]
[TD]
? (300)

<tbody>
</tbody>
[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]1150[/TD]
[TD]800[/TD]
[TD]600[/TD]
[TD]
? (500)

<tbody>
</tbody>
[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]2000[/TD]
[TD]1000[/TD]
[TD]25[/TD]
[TD]
? (975)

<tbody>
</tbody>
[/TD]
[/TR]
</tbody>[/TABLE]

This must be an old chesnut, but I can't work it out.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Assuming your data is sorted by account, you can simply test that:

=IF(B2=B1,E1+D2-C2,D2-C2)

assuming your posted data is in columns A:E with E being the formula column.
 
Upvote 0
Hey,

Try this formula in cell E2 (Balance column):
=SUMPRODUCT(($B$2:B2=B2)*($C$2:C2-$D$2:D2))
And drag that down the E column (Assuming that B is your Account number and C & D are Dr and Cr respectively.
 
Upvote 0
You can also try the below formula in E2 and drag down :

=SUMIF($B$2:B2,B2,$C$2:C2)-SUMIF($B$2:B2,B2,$D$2:D2)
 
Upvote 0
Many thanks, I'll give them a go.

The sumif looks similar to what I tried inc locked start ranges, although I always use sumifs these days even if only one crireria, but I always ended up with a nil value. I wonder if there was some corruption or I just messed up (latter probable ;)). I also played with sumproduct, but not above way.

Thanks again.
 
Last edited:
Upvote 0
Later...sumif/s works and as expected. I am sure sumproduct will work too but I find I understand sumif/s formula quicker when I look back later.

I am bemused why I failed yesterday.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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