How do I get sum product to ignore empty cells to calculate the cost basis of shares?

ExcelAdv

New Member
Joined
Mar 31, 2020
Messages
8
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. Mobile
Which formula of sum product should I put in the column C cells to calculate the cost basis of shares, which ignores the empty cells in column B and so considers only the prices in column A by which the quantity in column B is entered?
I tried to use the following formula, but it gives me the wrong result 1 instead of the right result 1,2712:
=SUMMENPRODUKT((A$2:A$30)*(B$2:B$30<>""))/SUMMEWENN(B2:B30;">0";A2:A30)

Whit the desired formula:
If I enter the first quantity 1 in cell B1, should appear the cost basis 1,2725 in cell C2
If I enter the second quantity 3 in cell B8, should appear the cost basis 1,2721 in cell C8
If I enter the third quantity 4 in cell B17, should appear the cost basis 1,2712 in cell C17


Mappe1 (version 2).xlsb
ABCDEF
1PriceNumber of Long ContractsCost Basis
21,272511,2725
31,2724
41,2723
51,2722
61,2721
71,2720
81,271931,2721
91,2718
101,2717
111,2716
121,2715
131,2714
141,2713
151,2712
161,2711
171,271041,0000001,2712(right answer)
181,2709
191,2708
201,2707
211,2706
221,2705
231,2704
241,2703
251,2702
261,2701
271,2700
Tabelle1
Cell Formulas
RangeFormula
C2C2=A2*B2
C17C17=SUMPRODUCT((A$2:A$30)*(B$2:B$30<>""))/SUMIF(B2:B30,">0",A2:A30)
A3:A27A3=A2-0.0001
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Excuse me. This was the mini sheet I wanted to upload. Please disregard the previous:

Mappe1 (version 2).xlsb
ABCDEF
1PriceNumber of Long ContractsCost Basis
21,272511,2725
31,2724
41,2723
51,2722
61,2721
71,2720
81,271931,2721
91,2718
101,2717
111,2716
121,2715
131,2714
141,2713
151,2712
161,2711
171,2710
181,2709
191,2708
201,2707
211,2706
221,2705
231,2704
241,2703
251,2702
261,2701
271,2700411,2712(right answer)
281,2699
291,2698
301,2697
311,2696
321,2695
Tabelle1
Cell Formulas
RangeFormula
C2C2=A2*B2
C27C27=SUMPRODUCT(($A$2:A27)*(B$2:B27<>""))/SUMIF($B$2:B27,">0",$A$2:A27)
A3:A32A3=A2-0.0001
 
Upvote 0
In the meanwhile I solved it with a column to be hidden. If you have a more elegant solution with only a formula in column C, I would appreciate it.

Cell Formulas
RangeFormula
C32,C27,C7:C25,C2:C3C2=(IF(B2<>"",ROUND(SUM($E$2:E2)/(SUM($B$2:B2)),4),""))
A3:A32A3=A2-0.0001
E2:E32E2=A2*B2
 
Upvote 0
Is it something like this that you are after?
If not, please details how you cam up with 1.2712 as the "right answer" for row 27

Cell Formulas
RangeFormula
A3:A32A3=A2-0.0001
C2:C32C2=IF(B2="","",SUMPRODUCT(A$2:A2,B$2:B2)/SUM(B$2:B2))
 
Upvote 1
Solution
Is it something like this that you are after?
If not, please details how you cam up with 1.2712 as the "right answer" for row 27

Cell Formulas
RangeFormula
A3:A32A3=A2-0.0001
C2:C32C2=IF(B2="","",SUMPRODUCT(A$2:A2,B$2:B2)/SUM(B$2:B2))
Waw, Peter_SSs, exactly what I needed and very elegant and simple formula.
I don't know why was 1.2712 considered the "right" answer, maybe the author considered some slippage or something else.
Anyway your solution is great. Many thanks :)
 
Upvote 0
You're welcome. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

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