Nesting SUMIF within SUMPRODUCT

S

sj2008

I'm trying to get a weighted average of columns E & H but only if the values
in column C match the values in column K. I tried nesting Sumif function
within sumproduct but this isn't working, it's just giving me a sum of colmn
H, not the weighted average. Any help would be appreciated.

=SUMPRODUCT(SUMIF($C$3:$C$320,K3,$E$3:$E$320),SUMIF($C$3:$C$320,$K3,$H$3:$H$320))/SUMIF($C$3:$C$320,K3,$E$3:$E$320)
 
S

Shane Devenshire

Hi,

My ranges are different but try something like this

=SUMPRODUCT(--(C2:C9=K2:K9),A2:A9*B2:B9)/SUMPRODUCT(B2:B9,--(C2:C9=K2:K9))

If this helps, please click the Yes button

Cheers,
Shane Devenshire
 
A

Aladin Akyurek

Control+shift+enter, not just enter...

=SUMPRODUCT(IF($C$3:$C$320=K3,$E$3:$E$320),IF($C$3:$C$320=K3,$H$3:$H$320))/SUMIF($C$3:$C$320,K3,$E$3:$E$320)

Is this what you intended?
 
D

DSSofMN

I have tried doing this and can only get the formula to recognize the first
cell in the array. What am I doing wrong?
 
B

Bernie Deitrick

Enter this formula using Ctrl-Shift-Enter and not just Enter

=SUMPRODUCT(IF($C$3:$C$320=K3,$E$3:$E$320)*IF($C$3:$C$320=$K3,$H$3:$H$320))/SUMIF($C$3:$C$320,K3,$E$3:$E$320)


HTH,
Bernie
MS Excel MVP
 
D

DSSofMN

Bernie - Thanks for your suggestion. The formula evaluated the first cell
which was a true condition and summed the entire column. I need the formula
to evaluate the entire column and sum the values that meet the condition.

Dan
 
B

Bernie Deitrick

Try it this way:

=SUMPRODUCT(($C$3:$C$320=K3)*$E$3:$E$320*$H$3:$H$320)/SUMIF($C$3:$C$320,K3,$E$3:$E$320)

HTH,
Bernie
MS Excel MVP
 
D

DSSofMN

I probably should have told you what I am trying to accomplish. I need to sum
a colum based on multiple criteria. The solution that you provided would work
if I was only evaluating one criteria. That's why I asked the question from
galimi's response. I was trying to do a sum(if based on multiple if
conditions.

Thanks,

Dan
 
B

Bernie Deitrick

For multiple criteria, use this style for AND requirements

=SUMPRODUCT(($C$3:$C$320=K3)*($D$3:$D$320=L3)*$E$3:$E$320*$H$3:$H$320)/SUMIF($C$3:$C$320,K3,$E$3:$E$320)

AND this for OR style

=SUMPRODUCT(($C$3:$C$320=K3)+($C$3:$C$320=K4))*$E$3:$E$320*$H$3:$H$320)/SUMIF($C$3:$C$320,K3,$E$3:$E$320)


HTH,

Bernie
 
B

Bernie Deitrick

Ooops, that second one needs an extra paren:

=SUMPRODUCT((($C$3:$C$320=K3)+($C$3:$C$320=K4))*$E$3:$E$320*$H$3:$H$320)/SUMIF($C$3:$C$320,K3,$E$3:$E$320)

Bernie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top