average cost per share problem

choubix

Board Regular
Joined
Jul 3, 2008
Messages
85
hello gentlemen!

I've a sticky problem at hand...
I need to calculate the average cost per share in a spreadsheet.
The average price works wonders when I only Buy stocks but the moment I sell stocks it changes my average cost of shares.

Basically I need to take the shares I sell out of the calculation...


My current formula is this one:

=SUMPRODUCT($G$10:$G$65000,$L$10:$L$65000,(SUBTOTAL(3,OFFSET($G$10,ROW($G$10:$G$65000)-MIN(ROW($G$10:$G$65000)),,))))/SUBTOTAL(9,$G$10:$G$65000)


I didnt write it myself but ti works when I Buy shares. I tweaked it (I dont understand what the subtotal() does exactly. it uses a counta() method)

For info:

Column G = Quantity (number of shares)
Column L = Price

now I need to be able to customize this formula so that it takes into account only the stocks that are Bought (Column E stores "B" or "S")

Can someone tell me how to tweak the formula so my average cost of share doesnt take into account the quantity and price in the calculation when Column E = "S" please?

Thanks in advance!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi

Try:

=SUMPRODUCT($G$10:$G$65000,$L$10:$L$65000,(SUBTOTAL(3,OFFSET($G$10,ROW($G$10:$G$65000)-MIN(ROW($G$10:$G$65000)),,))),--($E$10:$E$65000="B"))/SUMPRODUCT($G$10:$G$65000,(SUBTOTAL(3,OFFSET($G$10,ROW($G$10:$G$65000)-MIN(ROW($G$10:$G$65000)),,))),--($E$10:$E$65000="B"))
 
Upvote 0
Hello pgc01,

Thank you very much! this works well!!! you saved me a lot of aspirine today!

could I trouble you jsut a minute more please?
could you please help me understand this bit of the formula please?
the summ of simple functions makes something a bit too complex for me :(

(SUBTOTAL(3,OFFSET($G$10,ROW($G$10:$G$65000)-MIN(ROW($G$10:$G$65000)),,))),--($E$10:$E$65000="B"))

Thanks!!!!!
 
Upvote 0
I'm glad it helped.

The Subtotal bit is just to ensure that you only take into account the visible records when you filter.

I guess you are using filters and only want to consider the shares that result from the filters (or the person that wrote the formula was using filters).

Without the Subtotal the formula would consider all the shares in the rows 10:65000 whether they were filtered or not.
 
Upvote 0
it helped me big time... really. thanks!

I am indeed using filters, trying to bring some order in the chaos of our existing spreadsheets. ;)

Really thanks for helping me on this one!
 
Upvote 0

Forum statistics

Threads
1,214,994
Messages
6,122,633
Members
449,092
Latest member
bsb1122

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