Forum Discussion

K M's avatar
K M
Copper Contributor
Jun 25, 2018

Help Understanding a Formula

Hello Everyone - 

 

I found a formula that does exactly what I need, but I'm having a difficult time understanding how it's doing. 

 

Problem:
Find duplicates from Column A and sum corresponding numbers from Column E; find last entry of the duplicates and place the sum value. 

Column AColumn BColumn CColumn DColumn EColumn FFormula
   321936Test DataTest Data6/17/201777.75REG 
   321936Test DataTest Data7/1/201756.00REG 
   321936Test DataTest Data7/15/201757.75REG 
   321936Test DataTest Data7/29/201749.75REG 
   321936Test DataTest Data8/12/201772.50REG 
   321936Test DataTest Data8/26/201778.00REG 
   321936Test DataTest Data9/9/201779.50REG 
   321936Test DataTest Data9/9/20170.25AVWAG471.5
        

 

I found the following formula - 

=IF(AND(COUNTIF(A$2:A2,A3)=COUNTIF(A:A,A2),COUNTIF(A:A,A3)>1,SUMIF(A:A,A2,E:E), " ")

The formula works perfectly, but I'm not understanding how it's finding the last duplicate in the series of values. 

Any help breaking down the formula would be great - I'd prefer to know what's going on with the formula before using it freely.

 

Best, 

Kyle

  • Hi,

     

    You may take shorter range for your formula, e.g.

    =IF(AND(COUNTIF(A$2:A2,A2)=COUNTIF($A$1:$A$10,A2),COUNTIF($A$1:$A$10,A2)>1),SUMIF($A$1:$A$10,A2,$E$1:$E$10), "")

    stay on cell in in ribbon Formulas->Evaluate Formula to see how it works step by step.

    First COUNTIF(A$2:A2,A2) calculates how many times the value in A2 is repeated from first row till current one; second COUNTIF gives you how many such values in entire column A. If they are equal and third COUNTIF says you have more than one such value in column A (i.e. you ignore unique values) when you SUMIF column E for all such values in column A, otherwise return empty cell.

     

    Sample on shorter data is attached.

    • K M's avatar
      K M
      Copper Contributor

      Sergei - thank you for the breakdown. I guess I didn't understand them as well as I thought. Your explanation was perfect. Much appreciated. 

Resources