Calculate # repurchases within 30 days of last sale

M10Ant

New Member
Joined
Dec 30, 2021
Messages
36
Office Version
  1. 365
Platform
  1. Windows
Hoping someone might be able to help as currently at a loss on working out a formula for this

I need a formula that will count the number of times a stock has been bought within 30 days of the last sale of that stock.

In the below example, my summary table on the right should be recording a count of "2" for APPL stock and "1" for MSFT stock.

For the APPL stock, the count of 2 would come from the two Buy orders on 16/06/2021 and 22/07/2021, both being within 30 days of the last sale of APPL stock on 10/07/2021.
For the MFST stock, the count of 1 would come from the Buy order on 26/07/2021, being within 30 days of the last sale of MFST stock on 23/07/2021

No of repurchases within 30 days of last disposal.xlsx
ABCDEFG
1
2Trade Execution TimeOrder TypeStockStockNo. of Repurchases within 30 days of last sale
303/06/2021BuyAPPLAPPL
407/06/2021BuyAPPLMSFT
514/06/2021BuyMSFT
615/06/2021BuyAPPL
722/06/2021BuyMSFT
810/07/2021SellAPPL
916/07/2021BuyAPPL
1022/07/2021BuyAPPL
1123/07/2021SellMSFT
1226/07/2021BuyMSFT
1305/11/2021BuyMSFT
Sheet1


I think I might need to use COUNTIFS or MAX, but so far have only worked out how to count the number of trades for each different type of stock, not a count of all buy orders within 30 days of the last sale (per each type of stock).
I'm also running Excel 365 so have access to the new MINIFS, MAXIFS functions. I just can't work out how to solve this currently.



Thanks in advance.
 
A picture probably explains it a lot better! Below is what I'm trying to achieve:

1658436562741.png
 
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Sorry I appreciate I may not have explained the problem fully initially.
I'm needing a formula that records the number of buys of the same stock that has occurred within 30 days following a sell order for that stock prior, and for any time this has occurred.
Yes, that is a very different requirement to the initial explanation! :eek:

I would add another column to the first table. You can hide the column if you want.

M10Ant_1.xlsm
ABCDEFGH
1
2Trade Execution TimeOrder TypeStockRebuy within 30 daysStockNo. of Repurchases within 30 days of last sale
33/06/2021BuyAPPL APPL2
47/06/2021BuyAPPL MSFT2
514/06/2021BuyMSFT 
615/06/2021BuyAPPL 
722/06/2021BuyMSFT 
810/07/2021SellAPPL 
916/07/2021BuyAPPL1
1022/07/2021BuyAPPL1
1123/07/2021SellMSFT 
1226/07/2021BuyMSFT1
135/11/2021BuyMSFT 
146/12/2021SellMSFT 
1510/12/2021BuyMSFT1
16
Bought
Cell Formulas
RangeFormula
H3:H4H3=SUMIF(Table1[Stock],[@Stock],Table1[Rebuy within 30 days])
E3:E15E3=LET(tet,[Trade Execution Time],ctet,[@[Trade Execution Time]],IF([@[Order Type]]="Buy",IF(ctet-IFERROR(AGGREGATE(14,6,tet/((tet<ctet)*([Stock]=[@Stock])*([Order Type]="Sell")),1),0)<=30,1,""),""))
 
Upvote 0
Solution
Thank you very much Peter :) I've tested on my end and it's exactly what I need.
 
Upvote 0
Glad we got there in the end. 😁
Thanks for the confirmation.
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,435
Members
452,326
Latest member
johnshaji

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