Google Sheet Function updated for Excel

dmcmaste

New Member
Joined
Mar 31, 2020
Messages
15
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
I am trying to replicated this Google Sheet in Excel. I can't get the array/filter functionality in Column I, L working correctly in Excel. Can anyone please help replicate/troubleshoot.


For Column I - if it is the first time buying the stock previous units should be 0 otherwise added Transacted Units (Column D) to the previously bought Cumulative Unites (Column J).
Fol Column L - If it is the first time buying the stock it should be 0 otherwise it should be the previous Cumulative Cost (Column O) and added to the new transacted value (Column K)


Thanks!
 
Would you be able to manually calculate the results for your example then enter them into the sheet so that I have something to aim at?
To someone who deals with stock investment all day is is probably quite obvious, to me not so much.

I put something simple together to show you some numbers but it would need to look up the STOCK like how we did in I2/J2 above.


Book1
ABCDEFGHIJKLMNOPQRST
1DateTypeStockTransacted UnitsTransacted Price (per unit)Avg. PriceFeesStock Split RatioPrevious UnitsCumulative UnitsTransacted ValuePrevious CostCost of TransactionCost of Transaction (per unit)Cumulative CostGains/Losses from SaleRealised Gains/Losses %Cumulative Cost by TickerGains/Losses from Sale by TickerRealised Gains/Losses % by Ticker
212/10/2018DepositCASH1159,570.56-01      Error0 0.00#DIV/0!
312/31/2018InterestCASH166.84-01      Error0 0.00#DIV/0!
41/15/2019BuyAXP5090900105045000--45000 0.00#DIV/0!
51/16/2019BuyAAPL351501500103552500--52500 0.00#DIV/0!
61/17/2019BuyAXP1003050015015030004500--75000 0.00#DIV/0!
72/14/2019SellAAPL35170-01350595052505250150070013%5250.00700.0013%
82/19/2019BuyAAPL101001000101010000--10000 0.00#DIV/0!
92/20/2019BuyAAPL209093.3301103018001000--28000 0.00#DIV/0!
103/2/2020SellAAPL30230-0130069002800280093.3333333304100146%80504800.0060%
Sheet2
Cell Formulas
RangeFormula
I2:I10I2=IF((AND(B2<>"Deposit", B2<>"Interest", B2<>"DIV")), IFERROR(LOOKUP(2,1/(C$1:C1=C2),J$1:J1),0),"")
J2:J10J2=IF((AND(B2<>"Deposit", B2<>"Interest", B2<>"DIV")),IF(B2="Buy",I2+D2,IF(B2="Sell",I2-D2,IF(OR(B2="Div",B2="Fee"),I2,IF(B2="Split",I2*H2,0)))),"")
K2:K10K2=IF((AND(B2<>"Deposit", B2<>"Interest", B2<>"DIV")), IF(B2="Buy",E2*D2+G2,IF(B2="Sell",E2*D2-G2,E2*D2-G2)), "")
L2:L10L2=IF((AND(B2<>"Deposit", B2<>"Interest", B2<>"DIV")),IFERROR(LOOKUP(2,1/(C$1:C1=C2),O$1:O1),0),"")
M2:M10M2=IF((AND(B2<>"Deposit", B2<>"Interest", B2<>"DIV")),IF(B2="Sell",IF(I2=0,0,D2/I2*L2),"-"),"")
N2:N10N2=IF((AND(B2<>"Deposit", B2<>"Interest", B2<>"DIV")),IF(B2="Sell",IF(I2=0,0,L2/I2),"-"),"")
O2:O10O2=IF(B2="Buy",L2+K2,IF(OR(B2="Div",B2="Fee"),L2,IF(B2="Sell",IF(L2<=0,"Error.No Previous units.",L2-M2),IF(B2="Split",L2,"Error"))))
P2:P10P2=IF(B2="Sell",K2-M2,IF(OR(B2="Div",B2="Fee"),K2,0))
Q2:Q10Q2=IF(B2="Sell",(K2-M2)/M2,"")
S2:S9S2=P2
T2:T10T2=S2/R2
R7R7=M7
R10R10=M10+M7
S10S10=P10+P7
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
That's all I needed, it was just to clarify what was needed rather than me making a number of wrong guesses, think this should be somewhere close.

R2 =IF(B2="Sell",SUMIFS(M$2:M2,B$2:B2,"Sell",C$2:C2,C2),"")
S2 =IF(B2="Sell",SUMIFS(P$2:P2,B$2:B2,"Sell",C$2:C2,C2),"")
T2 =IF(S2="","",IFERROR(S2/R2,0))
 
Upvote 0
That's all I needed, it was just to clarify what was needed rather than me making a number of wrong guesses, think this should be somewhere close.

R2 =IF(B2="Sell",SUMIFS(M$2:M2,B$2:B2,"Sell",C$2:C2,C2),"")
S2 =IF(B2="Sell",SUMIFS(P$2:P2,B$2:B2,"Sell",C$2:C2,C2),"")
T2 =IF(S2="","",IFERROR(S2/R2,0))

This looks like it is working. I will check it out. Thanks for all the help!
 
Upvote 0
Hi I am trying to fill in column G2. Basically I want to look up Ticker BA (Cell B2) and reference column K & L. It should look up BA in column L and look at all Buys (Column K) and return max Cumulative Cost (Co9umn X).

In this example BA should return $7,17.00 (Cell X18)

Robinhood Portfolio.xlsx
ABCDEFGHIJKLMNOPQRSTUVWX
1COMPANYTICKERLASTCHANGECHANGE %POSITIONCOST BASISMARKET VALUEDateTypeStockTransacted UnitsTransacted Price (per unit)Avg. PriceFeesStock Split RatioPrevious UnitsCumulative UnitsTransacted ValuePrevious CostCost of TransactionCost of Transaction (per unit)Cumulative Cost
2Boeing Co (XNYS:BA)BA#####6.474.3620.0003094.62#######BuyAAPL35.000154.70154.700.001.00035.005,414.500--5,414.50
3Blackstone Group Inc (XNYS:BX)BX#####1.553.33102.6824939.00#######BuyVGR500.00010.8010.800.001.000500.005,400.000--5,400.00
4Canopy Growth Corp (XNYS:CGC)CGC#####0.533.69400.0005952.00#######BuyAAPL0.150170.20154.770.001.003535.1525.535414.5--5,440.03
5Delta Air Lines Inc (XNYS:DAL)DAL#####1.657.37100.0002396.50#######BuyBA20.000380.85380.850.001.00020.007,617.000--7,617.00
6First Trust Dow Jones Internet Index Fund (ARCX:FDN)FDN#####2.531.9925.0003238.75#######DivVGR500.0000.40-0.001.00500500.00200.0054005,400.00
7First Trust US Equity Opportunities ETF (ARCX:FPX)FPX#####1.181.8450.0003265.05#######BuyAAPL0.144187.83154.900.001.0035.1535.2927.055440.03--5,467.08
8First Trust International Equity Opportunities ETF (XNAS:FPXI)FPXI#####0.320.86100.0003734.00#######DivBA1.00041.10-0.001.002020.0041.1076177,617.00
9General Electric Co (XNYS:GE)GE $ 7.34 0.121.66900.0006606.00#######DivVGR1.000200.00-0.001.00500500.00200.0054005,400.00
10iShares Russell 2000 ETF (ARCX:IWM)IWM#####4.003.5525.0002915.25#######BuyAAPL0.130208.34155.100.001.0035.29435.4227.085467.08--5,494.16
11Southwest Airlines Co (XNYS:LUV)LUV#####3.6711.9350.0001719.25#######DivBA1.00041.10-0.001.002020.0041.1076177,617.00
12Legg Mason Low Volatility High Dividend ETF (XNAS:LVHD)LVHD#####0.853.26150.0004039.59#######DivVGR1.00025.00-0.001.00500500.0025.0054005,400.00
13#######DivVGR1.000200.00-0.001.00500500.00200.0054005,400.00
14#######BuyAAPL0.104261.90155.410.001.0035.42435.5327.245494.16--5,521.40
15#######DivBA1.00041.10-0.001.002020.0041.1076177,617.00
16#######DivVGR1.000210.00-0.001.00500500.00210.0054005,400.00
17#######BuyAAPL0.085322.12155.810.001.0035.52835.6127.385521.4--5,548.78
18#######DivBA1.00041.10-0.001.002020.0041.1076177,617.00
19#######SellAAPL35.000254.00-0.001.0035.6130.618,890.005548.785,453.27155.8195.51
20#######DivVGR1.000105.00-0.001.00500500.00105.0054005,400.00
21#######SellAAPL0.613254.00-0.001.000.6130.00155.7095.510195.51155.810.00
Sheet2
Cell Formulas
RangeFormula
B2:B12B2=A2.[Ticker symbol]
C2:C12C2=A2.Price
D2:D12D2=A2.Change
E2:E12E2=A2.[Change (%)]*100
F2:F12F2=MAX(IF('TRANS⇝Rollover IRA'!$C$2:$C$1000=$B2,'TRANS⇝Rollover IRA'!$J$2:$J$1000))
H2:H12H2=F2*C2
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Would you be able to manually calculate the results for your example then enter them into the sheet so that I have something to aim at?
To someone who deals with stock investment all day is is probably quite obvious, to me not so much.

Apologies. I referenced the cells of the values and made the example easier to read.

Robinhood Portfolio.xlsx
BCDEFGHIJKLMNOPQRSTUVWX
1TICKERLASTCHANGECHANGE %POSITIONCOST BASISMARKET VALUEDateTypeStockTransacted UnitsTransacted Price (per unit)Avg. PriceFeesStock Split RatioPrevious UnitsCumulative UnitsTransacted ValuePrevious CostCost of TransactionCost of Transaction (per unit)Cumulative Cost
2BA $ 142.68 -5.58-3.7720.0007617.002853.502019-01-16BuyAAPL35.000154.70154.700.001.00035.005,414.500--5,414.50
3VGR $ 9.90 -0.51-1.10500.0005400.004950.002019-02-11BuyVGR500.00010.8010.800.001.000500.005,400.000--5,400.00
42019-02-14BuyAAPL0.150170.20154.770.001.003535.1525.535414.5--5,440.03
52019-03-15BuyBA20.000380.85380.850.001.00020.007,617.000--7,617.00
62019-03-28DivVGR500.0000.40-0.001.00500500.00200.0054005,400.00
72019-05-16BuyAAPL0.144187.83154.900.001.0035.1535.2927.055440.0306--5,467.08
82019-06-07DivBA1.00041.10-0.001.002020.0041.1076177,617.00
92019-06-27DivVGR1.000200.00-0.001.00500500.00200.0054005,400.00
102019-08-15BuyAAPL0.130208.34155.100.001.0035.29435.4227.085467.0779--5,494.16
112019-09-06DivBA1.00041.10-0.001.002020.0041.1076177,617.00
122019-09-27DivVGR1.00025.00-0.001.00500500.0025.0054005,400.00
132019-09-27DivVGR1.000200.00-0.001.00500500.00200.0054005,400.00
142019-11-14BuyAAPL0.104261.90155.410.001.0035.42435.5327.245494.1624--5,521.40
152019-12-06DivBA1.00041.10-0.001.002020.0041.1076177,617.00
162019-12-30DivVGR1.000210.00-0.001.00500500.00210.0054005,400.00
172020-02-13BuyAAPL0.085322.12155.810.001.0035.52835.6127.385521.4001--5,548.78
182020-03-06DivBA1.00041.10-0.001.002020.0041.1076177,617.00
192020-03-30SellAAPL35.000254.00-0.001.0035.6130.618,890.005548.78065,453.27155.8195.51
202020-03-30DivVGR1.000105.00-0.001.00500500.00105.0054005,400.00
212020-04-01SellAAPL0.613254.00-0.001.000.6130.00155.7095.51013795.51155.810.00
Sheet2
Cell Formulas
RangeFormula
B2B2=A2.[Ticker symbol]
C2C2=A2.Price
D2:D3D2=A2.Change
E2:E3E2=A2.[Change (%)]*100
F2:F3F2=MAX(IF('TRANS⇝Rollover IRA'!$C$2:$C$1000=$B2,'TRANS⇝Rollover IRA'!$J$2:$J$1000))
G2G2=X18
H2:H3H2=F2*C2
G3G3=X20
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
For office 365 =MAXIFS(X:X,L:L,B2)

Not sure where column K and buy come into the equation as X18 doesn't meet that requirement, if it should be X5 then =MAXIFS(X:X,L:L,B2,K:K,"Sell")
 
Upvote 0
For office 365 =MAXIFS(X:X,L:L,B2)

Not sure where column K and buy come into the equation as X18 doesn't meet that requirement, if it should be X5 then =MAXIFS(X:X,L:L,B2,K:K,"Sell")

Really Appreciate your help!
 
Upvote 0
You're welcome :)

Just noticed your other reply above as well, think you responded to an old post from last week (which you replied to in post 11)
Apologies. I referenced the cells of the values and made the example easier to read.
the same thing has caught me out a few times, when you click the thread link from your list of watched threads, it only takes you to the end if there are new replies, otherwise it just takes you to the first page.
 
Upvote 0
Hi have a new question around the same Sheet.

I am looking to get the latest open (Buy) position (Cell T5) in a Stock and latest cost basis (Cell U5) in my sheet. So for this example below, I want to display AAPL = 25 units not 75 which is what the function in cell T5 is in and Cell U5 should be 1,250. Currently it is just getting the Max value in the range not the latest open Buy position. Thanks for the help!


My Portfolio (4-9-20).xlsx
ABCDEFGHIJKLMNOPQRSTU
1DateTypeStockTransacted UnitsTransacted Price (per unit)Avg. PriceFeesStock Split RatioPrevious UnitsCumulative UnitsTransacted ValuePrevious CostCost of TransactionCost of Transaction (per unit)Cumulative CostGains/Losses from SaleRealised Gains/Losses %
22020-01-01DepositTR 401k Rollover1.00050,000.00-0.001.00      Error0.00 
32020-04-01BuyAAPL75.000100.00100.000.001.00075.007,500.000--7,500.000.00 
42020-04-07BuyWMT10.00025.0025.000.001.00010.00250.000--250.000.00 TickerMAX PositionCost Basis
52020-04-10SellAAPL75.000125.00-0.001.00750.009,375.0075007,500.00100.000.001875.0025.00%AAPL757500
62020-05-01BuyBBY25.00010.0010.000.001.00025.00250.000--250.000.00 
72020-05-05BuyAAPL25.00050.0050.000.001.00025.001,250.000--1,250.000.00 
Trans.Roll (2)
Cell Formulas
RangeFormula
I2:I7I2=IF((AND(B2<>"Deposit", B2<>"Interest")), IFERROR(LOOKUP(2,1/(C$1:C1=C2),J$1:J1),0),"")
J2:J7J2=IF(B2<>"Deposit",IF(B2="Buy",I2+D2,IF(B2="Sell",I2-D2,IF(OR(B2="Div",B2="Fee"),I2,IF(B2="Split",I2*H2,0)))),"")
K2:K7K2=IF((AND(B2<>"Deposit", B2<>"Interest")), IF(B2="Buy",E2*D2+G2,IF(B2="Sell",E2*D2-G2,E2*D2-G2)), "")
L2:L7L2=IF((AND(B2<>"Deposit", B2<>"Interest")), IFERROR(LOOKUP(2,1/(C$1:C1=C2),O$1:O1),0),"")
M2:M7M2=IF((AND(B2<>"Deposit", B2<>"Interest", B2<>"DIV")),IF(B2="Sell",IF(I2=0,0,D2/I2*L2),"-"),"")
N2:N7N2=IF((AND(B2<>"Deposit", B2<>"Interest", B2<>"DIV")),IF(B2="Sell",IF(I2=0,0,L2/I2),"-"),"")
O2:O7O2=IF(B2="Buy",L2+K2,IF(OR(B2="Div",B2="Fee"),L2,IF(B2="Sell",IF(L2<=0,"Error.No Previous units.",L2-M2),IF(B2="Split",L2,"Error"))))
Q2:Q7Q2=IF(B2="Sell",K2-M2,IF(OR(B2="Div",B2="Fee"),K2,0))
R2:R7R2=IF(B2="Sell",(K2-M2)/M2,"")
T5T5=MAX(IF($C$2:$C$1000=$S5,$J$2:$J$1000))
U5U5=MAXIFS($O$2:$O$1001,$C$2:$C$1001,S5)
F2:F7F2=IF(B2="BUY", O2/J2, "-")
Press CTRL+SHIFT+ENTER to enter array formulas.
Cells with Conditional Formatting
CellConditionCell FormatStop If True
R1:R7,R41:R1048576Cell Value<0textNO
B:BCell Valuecontains "Buy"textNO
B:BCell Valuecontains "Sell"textNO
 
Upvote 0
Try

=IFERROR(LOOKUP(2,1/($C$2:$C$1000=$S5)/($B$2:$B$1000="buy"),$J$2:$J$1000),"")

=IFERROR(LOOKUP(2,1/($C$2:$C$1000=$S5)/($B$2:$B$1000="buy"),$O$2:$O$1000),"")
 
Upvote 0

Forum statistics

Threads
1,216,098
Messages
6,128,812
Members
449,468
Latest member
AGreen17

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