0
votes

I would like to achieve the following in Excel:

The formula should sum all the values of a column in case the values in the reference column are duplicates, and if there are duplicates, then only the value of the second duplicate should be summed:

Column A (reference IDs)   
A1: abc   
A2: ade                
A3: afe                
A4: age                
A5: age                

Column B (values for Sum)
B1: 2
B2: 3
B3: 4
B4: 5
B5: 800

The result of the formula should be: 2 + 3 + 4 + 800 = 809 and not 2 + 3 + 4 + 5 = 14.

This is because the references in cell A4 and A5 are duplicates, and only the second duplicate in the reference column should be used.

1

1 Answers

0
votes

You can also do it without a helper column, if you really need to.

Assuming the data as you give it is in A1:B5, array formula**:

=SUM(IF(COUNTIF(A1:A5,A1:A5)>1,IF(MATCH(A1:A5,A1:A5,0)<>ROW(A1:A5)-MIN(ROW(A1:A5))+1,B1:B5),B1:B5))

Regards

**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).