Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel - How do I create a cumulative sum column within a group?

In Excel, I have an hours log that looks like this:

PersonID   Hours   JobCode
1          7       1
1          6       2
1          8       3
1          10      1
2          5       3
2          3       5
2          12      2
2          4       1

What I would like to do is create a column with a running total, but only within each PersonID so I want to create this:

PersonID   Hours   JobCode    Total
1          7       1          7 
1          6       2          13
1          8       3          21
1          10      1          31
2          5       3          5
2          3       5          8
2          12      2          20
2          4       1          24

Any ideas on how to do that?

like image 424
Ryan Avatar asked Feb 18 '16 23:02

Ryan


2 Answers

In D2 and fill down:

=SUMIF(A$2:A2,A2,B$2:B2)
like image 159
Tim Williams Avatar answered Oct 11 '22 02:10

Tim Williams


Assuming that your data starts in cell A1, this formula will accumulate the hours until it finds a change in person ID.

=IF(A2=A1,D1+B2,B2)

Put the formula in cell D2, and copy down for each row of your data.

like image 2
DeanOC Avatar answered Oct 11 '22 03:10

DeanOC