# Sumproduct In Excel

#### varunwalla

##### New Member
Hello everyone,

I need to calculate the average price of a product let say Orange.

1. First 30 Qty of Orange is bought at 8.85 so the value becomes 265.50
2. Next 5 Qty of Orange is bought at 8.75 so the value becomes 43.75
3. Total cost of 35 Qty is 309.25
4. Now taking the average value of 35 is 8.84 ( rounding to 2 digit ) i.e 309.25 divide by 35

At the moment i am using this procedure to calculate the average value

Code:
``=SUMPRODUCT(E3+E4)/(C3+C4)*(B3="Orange")``

is there any techniques to simplify this for each product i am manuly entering the reference cells for apple i am entering it as

Code:
``=SUMPRODUCT(E2+E5)/(C2+C5)*(B5="Apple")``

is there any formula to simplify these steps

Sumproduct.xlsx
ABCDEFGHI
1S.NoProduct NameQuantityPriceTotal PriceAverage Price CostTotal Investment Cost
21Apple5198.00990.00Orange8.84Orange
32Orange308.85265.50Apple204.00Apple
43Orange58.7543.75
54Apple5210.001050.00
Sheet 1
Cell Formulas
RangeFormula
G2G2=SUMPRODUCT(E3+E4)/(C3+C4)*(B3="Orange")
G3G3=SUMPRODUCT(E2+E5)/(C2+C5)*(B5="Apple")
A3:A5A3=(A2+1)
E2:E5E2=(C2*D2)

Any help would be much appreciated

#### RoryA

##### MrExcel MVP, Moderator
It's SUMIF, not SUM in I2.

### Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

#### varunwalla

##### New Member
One more thing tired out is to try out If function i.e c3=sale then in h2 the calculation should be ignored too much if function googled out like if, countif, nested if what to try out i.e the value in h2 should be display as 8.84

Sumproduct.xlsx
ABCDEFGHIJ
1S.NoProduct NameTypeQuantityPriceTotal PriceAverage Price CostTotal Investment Cost
21ApplePurchase5198.00990.00Orange9.17Orange641.75
32OrangePurchase308.85265.50Apple204Apple2040.00
43OrangePurchase58.7543.75
54ApplePurchase5210.001050.00
65OrangeSale359.50332.50
Sheet 1
Cell Formulas
RangeFormula
H2:H3H2=ROUND(SUMIF(\$B:\$B,\$G2,\$F:\$F)/SUMIF(\$B:\$B,\$G2,\$D:\$D),2)
J2:J3J2=SUMIF(\$B:\$B,\$I2,\$F:\$F)
A3:A6A3=(A2+1)
F2:F6F2=(D2*E2)

#### RoryA

##### MrExcel MVP, Moderator
You need SUMIFS for multiple criteria:

=ROUND(SUMIFS(\$F:\$F,\$B:\$B,\$G2,\$C:\$C,"<>Sale")/SUMIFS(\$D:\$D,\$B:\$B,\$G2,\$C:\$C,"<>Sale"),2)

Note that with SUMIFS, the range to sum goes first, not last.

Replies
5
Views
215
Replies
6
Views
217
Replies
4
Views
908
Replies
13
Views
303
Replies
7
Views
163

1,127,595
Messages
5,625,697
Members
416,128
Latest member
WarJamAnd

### 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.

### Which adblocker are you using?

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

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