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:


<tbody>
[TD="align: center"] A [/TD]
[TD="align: center"] B [/TD]
[TD="align: center"] C [/TD]
[TD="align: center"] D [/TD]

[TD="align: center"] Quarter
[/TD]
[TD="align: center"] Transaction Type
[/TD]
[TD="align: center"] Quantity
[/TD]
[TD="align: center"] Price
[/TD]

[TD="align: center"]Q1 2016[/TD]
[TD="align: center"]Trade[/TD]
[TD="align: center"]2000[/TD]
[TD="align: center"]$68.00[/TD]

[TD="align: center"]Q1 2016[/TD]
[TD="align: center"]Validation[/TD]
[TD="align: center"]500[/TD]
[TD="align: center"][/TD]

[TD="align: center"]Q1 2016[/TD]
[TD="align: center"]Trade[/TD]
[TD="align: center"]400[/TD]
[TD="align: center"]$70.00[/TD]

[TD="align: center"]Q1 2016[/TD]
[TD="align: center"]Trade[/TD]
[TD="align: center"]200[/TD]
[TD="align: center"]$120.00[/TD]

[TD="align: center"]Q2 2016[/TD]
[TD="align: center"]Validation[/TD]
[TD="align: center"]1000[/TD]
[TD="align: center"][/TD]

</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

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
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,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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