how do i compare rows within each group?

seagreen

Board Regular
Joined
Feb 7, 2009
Messages
71
Hello,
How would I calculate the value of colB[row2]-colB[row1] for a group of records/rows in Excel but only within that group of records? In other words, if a value in A changes, don't do the calculation between the first row of the new value and the last value of the previous value in A.

Ex:
ssn

1111111 89
1111111 98 9
1111111 55 -43


2222222 9
2222222 52 43
2222222 17 -35
2222222 33 16
2222222 10 -23

4444444 22
4444444 11 -11

Thanks for any help!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Assuming your data is in columns A and B and starts on row 2, then enter this formula in C2 and copy down for all rows:

=IF(A2=A1,B2-B1,"")
 
Upvote 0
I'm not sure I completely underdtand what you are asking? Are there spaces between these groups I assume?

Why can you not use a simple subtraction formula subtracting the last 2 cells?
 
Upvote 0
I'm not sure I completely underdtand what you are asking? Are there spaces between these groups I assume?

Why can you not use a simple subtraction formula subtracting the last 2 cells?
Thanks schielm, I have an increased row height between each group but I see what you mean about how this would work if I had a blank row instead.
 
Upvote 0
The formula I gave you will work whether or not you have blank rows between your data sets. If there is only one blank row, it will work just fine. If there is more than one, it will still work but return a 0 for each 2nd (or 3rd, etc) consecutive blank row.

If you had that situation, it could be easily rectified with a slight modification:

=IF(AND(LEN(A2)>0,A2=A1),B2-B1,"")
 
Upvote 0
The formula I gave you will work whether or not you have blank rows between your data sets. If there is only one blank row, it will work just fine. If there is more than one, it will still work but return a 0 for each 2nd (or 3rd, etc) consecutive blank row.

If you had that situation, it could be easily rectified with a slight modification:

=IF(AND(LEN(A2)>0,A2=A1),B2-B1,"")


Thanks Joe4. I don't have any blank rows. Your solution works regardless of whether there are blank rows as you said and I used it. When the other poster offered his solution, I had already used your solution but I saw how his solution would work if I had blank rows. Thanks again.
 
Upvote 0

Forum statistics

Threads
1,215,011
Messages
6,122,677
Members
449,092
Latest member
tayo4dgacorbanget

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