Sum Second Occurrence, if there is one, with criteria

gberg

Board Regular
Joined
Jul 16, 2014
Messages
180
Office Version
  1. 365
Platform
  1. Windows
I am trying to get a formula that will take the second occurrence of a name in column A. If there is no second occurrence then the unique value should be used. The other part of it is that each name will start with a letter of the alphabet (i.e. A, B, C, D, etc.) I need the formula to sum only the "D's" or "E's" together. I have found a formula that accomplishes the first goal of taking the second occurrence but I can't make it look up the "D" or "E" to group by these designations. On the following example I have highlighted the items that I want summed. Cells C25 and C26 are the outcomes I am looking for. Any help would be greatly appreciated.




Book1.xlsx
ABC
1TOTAL VALUE
2Project Value
3D0001100,000
4D0002110,000
5D0003120,000
6D0004130,000
7E0001140,000
8E0002150,000
9E0003160,000
10E0004170,000
11E0005180,000
12E0006190,000
13
14WORK IN PLACE
15Project Value
16D00011,000
17D00044,000
18E00015,000
19E00026,000
20E00059,000
21E000610,000
22
23
24
25D595,000235,000
26E595,000360,000
Sheet1
Cell Formulas
RangeFormula
B25B25=SUM(IF((COUNTIF(A3:A21,A3:A21)>1),IF(MATCH(A3:A21,A3:A21,0)<>ROW(A3:A21)-MIN(ROW(A3:A21))+1,B3:B21),B3:B21))
C25C25=B4+B5+B16+B17
B26B26=SUM(IF((COUNTIF(A3:A21,A3:A21)>1),IF(MATCH(A3:A21,A3:A21,0)<>ROW(A3:A21)-MIN(ROW(A3:A21))+1,B3:B21),B3:B21))
C26C26=B9+B10+B18+B19+B20+B21
 
You all have been a big help, thanks for everyone's assistance. I've tried both and they work well and have me all set!
 
Upvote 0

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Glad we could help & thanks for the feedback.
I had taken the statement in post 1 as meaning that there could be more than 2 occurrences
Interesting how we can all see things differently, as I took it to mean there would only be one or two occurrences.
 
Upvote 0
as I took it to mean there would only be one or two occurrences.
With that in mind, I went back to finish an idea that I abandoned earlier. I was trying similar with XLOOKUP but it refuses to return a 2 column array ?
Book1
AB
1TOTAL VALUE
2Project Value
3D0001100000
4D0002110000
5D0003120000
6D0004130000
7E0001140000
8E0002150000
9E0003160000
10E0004170000
11E0005180000
12E0006190000
13
14WORK IN PLACE
15Project Value
16D00011000
17D00044000
18E00015000
19E00026000
20E00059000
21E000610000
22
23
24
25D235000
26E360000
Sheet2
Cell Formulas
RangeFormula
B25:B26B25=SUM(UNIQUE(FILTER(INDEX($A$3:$B$21,XMATCH($A$3:$A$21,$A$3:$A$21,0,-1),{1,2}),LEFT($A$3:$A$21)=A25,"")))
 
Upvote 0
I was trying similar with XLOOKUP but it refuses to return a 2 column array
Interesting, it does if you lookup a single value, but not if you lookup an array ?
 
Upvote 0
Maybe because in there is only 1 row to return with a single value?

I've got a working version by changing the order of events in the formula. By filtering first, this should improve efficiency as well as there are less exact matches to process.
Excel Formula:
=SUM(XLOOKUP(UNIQUE(FILTER($A$3:$A$21,LEFT($A$3:$A$21)=A25)),$A$3:$A$21,$B$3:$B$21,,0,-1))
 
Upvote 0
Here's a slightly longer way, but it handles more than 2 values:

Excel Formula:
=SUM(FILTER(B$3:B$21,(LEFT(A$3:A$21)=A25)*((MATCH(A$3:A$21&"",A$3:A$21&"",0)<SEQUENCE(ROWS(A$3:A$21)))+(COUNTIF(A$3:A$21,A$3:A$21)=1))))
 
Upvote 0

Forum statistics

Threads
1,215,503
Messages
6,125,179
Members
449,212
Latest member
kenmaldonado

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