Multi-Condition Weighted Average Formula

TheDragonExp

New Member
Joined
Dec 18, 2015
Messages
4
Hello,

I have a large data set and I am trying to calculate the weighted average price subject to two conditions. I know I can use SUMPRODUCT to accomplish this without the conditions, but is there anyway to make it work subject to conditions? I am hoping to be able to do this using a formula in a single cell. The table below shows an example of my data:

ABCD
Quarter
Transaction Type
Quantity
Price
Q1 2016Trade2000$68.00
Q1 2016Validation500
Q1 2016Trade400$70.00
Q1 2016Trade200$120.00
Q2 2016Validation1000

<tbody>
</tbody>

What I would like to do is find the weighted average price for each quarter (i.e. Q1 2016, Q2 2016, etc.) of only those entries that are trades. So for one of the weighted average calculations it would include every price/quantity entry that is listed as Q1 2016 and the transaction type is "Trade". You'll notice that some transaction types don't have a price.

I've tried to play around with this formula, but I'm stuck and wondering if this is even possible... ("Price, Quantity, etc." refer to the entire column being selected): =SUMPRODUCT((Price)*(Quantity))/(SUMIFS(Quantity, Quarter, Q1 2016, Transaction Type, Trade))

Using the SUMIFS function, I am able to sum the total quantity of units that are traded in the specified period, but I have no idea how to make the SUMPRODUCT function only take the price and quantities from trades that are in the specified period.

Any assistance would be greatly appreciated!
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Hi

In general the way people use SUMPRODUCT with conditions is you multiply a Boolean (true/false) from a formula that compares a column to a desired value, such as A2:A10 = "Q1 2016".

So you say SUMPRODUCT((A2:A10="Q1 2016")*(all of your other formulas)).

The A2:A10 returns something like {TRUE,TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,...}. The multiplication coerces the TRUE and FALSE into 1 and 0 so you end up with {1,1,1,1,0,0,...}. This then multiplies by your other formulas to return the normal result for TRUE and a zero for FALSE.

Hope that helps - let me know if you need anything cleared up or if I've not been clear

Mackers
 
Last edited:
Upvote 0
Hi

In general the way people use SUMPRODUCT with conditions is you multiply a Boolean (true/false) from a formula that compares a column to a desired value, such as A2:A10 = "Q1 2016".

So you say SUMPRODUCT((A2:A10="Q1 2016")*(all of your other formulas)).

The A2:A10 returns something like {TRUE,TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,...}. The multiplication coerces the TRUE and FALSE into 1 and 0 so you end up with {1,1,1,1,0,0,...}. This then multiplies by your other formulas to return the normal result for TRUE and a zero for FALSE.

Hope that helps - let me know if you need anything cleared up or if I've not been clear

Mackers

That works!! I came across posts using the SUMPRODUCT function like you described but I didn't understand how it was actually working, and thus couldn't replicate it. Thank you for taking the time to explain it to me! Cheers :)
 
Upvote 0
No problem. Your question was well-composed so I thought you might be the kind of person who prefers to have the understanding rather than just the answer.
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,700
Members
448,979
Latest member
DET4492

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