Small but hard Challenge

Morosho

New Member
Joined
Mar 10, 2015
Messages
3
Hey guys, I have been using excel for a long time now and I consider myself relatively good at it.

However I have been having a headache trying to solve a kind of complex weighted average in a table like this:

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Client name[/TD]
[TD]Broker[/TD]
[TD]Share[/TD]
[TD]Client&Share[/TD]
[TD]Quantity[/TD]
[TD]Avg Price (in Broker)[/TD]
[TD]Avg Price (Client)[/TD]
[/TR]
[TR]
[TD]Dan[/TD]
[TD]X[/TD]
[TD]AAPL[/TD]
[TD]DanAAPL[/TD]
[TD]100[/TD]
[TD]90[/TD]
[TD]formula?[/TD]
[/TR]
[TR]
[TD]Dan[/TD]
[TD]X[/TD]
[TD]T[/TD]
[TD]DanT[/TD]
[TD]50[/TD]
[TD]40[/TD]
[TD]?[/TD]
[/TR]
[TR]
[TD]Jhon[/TD]
[TD]Y[/TD]
[TD]AAPL[/TD]
[TD]JhonE[/TD]
[TD]80[/TD]
[TD]88[/TD]
[TD]?[/TD]
[/TR]
[TR]
[TD]Dan[/TD]
[TD]Y[/TD]
[TD]AAPL[/TD]
[TD]DanAAPL[/TD]
[TD]200[/TD]
[TD]95[/TD]
[TD]?[/TD]
[/TR]
[TR]
[TD]etc...[/TD]
[TD]etc...[/TD]
[TD]etc...[/TD]
[TD]etc...[/TD]
[TD]etc...[/TD]
[TD]etc...[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

The result for first row in column "Avg Price (Client)" would be ((100*90)+(200*95))/(100+200) = 93.33
It should also show the same result for row #4 in that formula (93.33)

Most clients have accounts in 3+ brokers, so that makes it a little more complicated... (in the example here it's only two)

I have some formula that gives an aprox value.. but I need the real weighted average.
Just to show I have tried, this is what I got: =IF([@Precio]=0;0;([@Cantidad]*[@Precio]+((SUMIF([D&A];[@[D&A]];[Cantidad])-[@Cantidad])*(SUMIF([D&A];[@[D&A]];[Precio])-[@Precio]))/(COUNTIF([D&A];[@[D&A]])-IF(COUNTIF([D&A];[@[D&A]])=1;0;1)))/SUMIF([D&A];[@[D&A]];[Cantidad]))

Anyone with some inspiration to help me?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Maybe?
Excel Workbook
ABCDEFG
1nameBrokerShareClient&ShareQuantityAvg Price (in Broker)Avg Price (Client)
2DanXAAPLDanAAPL1009093.33
3DanXTDanT504040.00
4JhonYAAPLJhonE808888.00
5DanYAAPLDanAAPL2009593.33
Sheet
 
Upvote 0
Man, you are great... I had not seen this "Range=Cell" trick before. Does this have a special name to start reading about it? Because it's Fing awesome!

Thanks!

Edit: what's the " -- " for? what does it do?
 
Last edited:
Upvote 0
Man, you are great... I had not seen this "Range=Cell" trick before. Does this have a special name to start reading about it? Because it's Fing awesome!
In general, the are "array formulas" which normally need to be array-entered pressing CTRL+SHIFT+ENTER instead of just Enter by itself; however, SUMPRODUCT is a special function in that it natively handles array formulas without the need to array-enter them. See here for more information on array formulas...

Array Formulas
 
Upvote 0
You're welcome, glad that worked for you. As per Morosho the -- just multiples the TRUE and FALSE by 1 to turn them into 1 and 0.
 
Upvote 0

Forum statistics

Threads
1,223,738
Messages
6,174,213
Members
452,551
Latest member
croud

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