Weighted average ignoring zero values in pivot

Zebhyr

New Member
Joined
May 2, 2016
Messages
4
First timer posting here!

I need to calculate average of material purchase prices, weighted by their mass, while ignoring zero values, in each factory separately. There are several different countries, factories and materials (and material & quality categories), but all the materials are measured in tons and are comparable. I would like to have the data in a pivot chart as it is easy to upkeep and visually presentable.

My data looks somewhat like this:
Country / FactoryID / MaterialID / Mass (tons) / Price ($/ton) / Total cost (Mass*Price)

Country1 / Factory1 / Material 1 / 1000 / 30 / 30000
Country1 / Factory1 / Material 2 / 1000 / 30 / 30000
Country1 / Factory1 / Material 3 / 1000 / 0 / 0

In this case, I am getting result in pivot table that the average material price would be 20 $/ton, when clearly the average price is 30 $/ton. Currently in pivot chart I'm calculating Average of (Total cost / Mass), but it is incorrect.

I was able to calculate the average cost correctly by VBA, but it gets frustrating when I would like to have it easily repeatable, and also filter by other criteria than the factoryID.

Any directions?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,215,391
Messages
6,124,673
Members
449,178
Latest member
Emilou

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