Trade Summary - Incremental Lookup / counting

GeeWhiz7

Board Regular
Joined
Nov 22, 2021
Messages
214
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi Gurus,
I've run into another thing I can't quite figure out. In the attached mini-sheet, there are columns with an example date, stock price and buy/sell that takes place.
The columns to the right are what I would like to achieve dynamically where,
  • each buy/sell pair equals a trade which is incremented automatically (ie trade 1, 2, 3...) based on the range of input data.
  • for each buy/sell pair the buy/sell date and price are captured all in a horizontal table.
I know how to grab things using vlookup, but not how to do things incrementally and I can't quite figure out in VBA how to use "Buy" to initiate the count column...
Thanks for your help.
-Will

TradeSummaryExample.xlsx
ABCDEFGHIJ
1DatePriceBuy/SellTrade #Buy DateSell DateBuy PriceSell Price
212/1/202012.35Buy112/1/202012/7/202012.3514.68
312/2/202012.21212/9/202012/12/202013.8415.99
412/3/202012.85312/15/202014.99
512/4/202012.01
612/5/202013.05
712/6/202013.55
812/7/202014.68Sell
912/8/202013.81
1012/9/202013.84Buy
1112/10/202015.22
1212/11/202015.78
1312/12/202015.99Sell
1412/13/202015.25
1512/14/202015.21
1612/15/202014.99Buy
1712/16/202014.11
1812/17/202014.05
Sheet1
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
MrExcelPlayground5.xlsx
ABCDEFGHIJ
1DatePriceBuy/SellTrade #Buy DateSell DateBuy PriceSell Price
212/1/202012.35Buy112/1/202012/7/202012.3514.68
312/2/202012.21212/9/202012/12/202013.8415.99
412/3/202012.85312/15/202014.99
512/4/202012.01
612/5/202013.05
712/6/202013.55
812/7/202014.68Sell
912/8/202013.81
1012/9/202013.84Buy
1112/10/202015.22
1212/11/202015.78
1312/12/202015.99Sell
1412/13/202015.25
1512/14/202015.21
1612/15/202014.99Buy
1712/16/202014.11
1812/17/202014.05
Sheet23
Cell Formulas
RangeFormula
F2:F4F2=SEQUENCE(COUNTIF(Table3[Buy/Sell],"Buy"))
G2:G4G2=FILTER(Table3[Date],Table3[Buy/Sell]="Buy","")
H2:H3H2=FILTER(Table3[Date],Table3[Buy/Sell]="Sell","")
I2:I4I2=FILTER(Table3[Price],Table3[Buy/Sell]="Buy","")
J2:J3J2=FILTER(Table3[Price],Table3[Buy/Sell]="Sell","")
Dynamic array formulas.
 
Upvote 0
Solution
Another possible option
+Fluff 1.xlsm
ABCDEFGHIJ
1DatePriceBuy/SellTrade #Buy DateSell DateBuy PriceSell Price
212/01/202012.35Buy112/01/202012/07/202012.3514.68
312/02/202012.21212/09/202012/12/202013.8415.99
412/03/202012.85315/12/202014.99
512/04/202012.01
612/05/202013.05
712/06/202013.55
812/07/202014.68Sell
912/08/202013.81
1012/09/202013.84Buy
1112/10/202015.22
1212/11/202015.78
1312/12/202015.99Sell
1413/12/202015.25
1514/12/202015.21
1615/12/202014.99Buy
1716/12/202014.11
1817/12/202014.05
19
Lists
Cell Formulas
RangeFormula
F2:J4F2=LET(f, FILTER(A2:B100,C2:C100<>""),r,ROWS(f),s,SEQUENCE(ROUNDUP(r/2,0),,,2),IFERROR(CHOOSE({1,2,3,4,5},ROUNDUP(s/2,0),INDEX(f,s,1),INDEX(f,s+1,1),INDEX(f,s,2),INDEX(f,s+1,2)),""))
Dynamic array formulas.

Although I'm sure there must be a simpler way than the final choose
 
Upvote 0
MrExcelPlayground5.xlsx
ABCDEFGHIJ
1DatePriceBuy/SellTrade #Buy DateSell DateBuy PriceSell Price
212/1/202012.35Buy112/1/202012/7/202012.3514.68
312/2/202012.21212/9/202012/12/202013.8415.99
412/3/202012.85312/15/202014.99
512/4/202012.01
612/5/202013.05
712/6/202013.55
812/7/202014.68Sell
912/8/202013.81
1012/9/202013.84Buy
1112/10/202015.22
1212/11/202015.78
1312/12/202015.99Sell
1412/13/202015.25
1512/14/202015.21
1612/15/202014.99Buy
1712/16/202014.11
1812/17/202014.05
Sheet23
Cell Formulas
RangeFormula
F2:F4F2=SEQUENCE(COUNTIF(Table3[Buy/Sell],"Buy"))
G2:G4G2=FILTER(Table3[Date],Table3[Buy/Sell]="Buy","")
H2:H3H2=FILTER(Table3[Date],Table3[Buy/Sell]="Sell","")
I2:I4I2=FILTER(Table3[Price],Table3[Buy/Sell]="Buy","")
J2:J3J2=FILTER(Table3[Price],Table3[Buy/Sell]="Sell","")
Dynamic array formulas.
This works for what I am trying to do since for my use there will always be a sell paired with a buy for the instrument. I didn't even think of doing it this way before so thank you James!
 
Upvote 0
Another possible option
+Fluff 1.xlsm
ABCDEFGHIJ
1DatePriceBuy/SellTrade #Buy DateSell DateBuy PriceSell Price
212/01/202012.35Buy112/01/202012/07/202012.3514.68
312/02/202012.21212/09/202012/12/202013.8415.99
412/03/202012.85315/12/202014.99
512/04/202012.01
612/05/202013.05
712/06/202013.55
812/07/202014.68Sell
912/08/202013.81
1012/09/202013.84Buy
1112/10/202015.22
1212/11/202015.78
1312/12/202015.99Sell
1413/12/202015.25
1514/12/202015.21
1615/12/202014.99Buy
1716/12/202014.11
1817/12/202014.05
19
Lists
Cell Formulas
RangeFormula
F2:J4F2=LET(f, FILTER(A2:B100,C2:C100<>""),r,ROWS(f),s,SEQUENCE(ROUNDUP(r/2,0),,,2),IFERROR(CHOOSE({1,2,3,4,5},ROUNDUP(s/2,0),INDEX(f,s,1),INDEX(f,s+1,1),INDEX(f,s,2),INDEX(f,s+1,2)),""))
Dynamic array formulas.

Although I'm sure there must be a simpler way than the final choose
This also works...I guess more than one way to skin the problem. I was trying to loop through the rows with vb and didn't even think of either of these approaches. I suppose if I mix ticker symbols or do something besides long-only trades then I might need to find another way. Thank you Fluff and James.
 
Upvote 0
Glad we could help & thanks for the feedback.

In future please mark the post that has helped you the most as the solution, not your post saying it works, I have changed it for you this time. Thanks
 
Upvote 0
If you had to mix in ticker symbols, it would just be another item in the FILTER.

When will I get the LET function?!
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,191
Members
452,616
Latest member
intern444

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