Filtering for First and Last day of the Year or Month from Years of Workdate Data

LakeDog

New Member
Joined
Oct 18, 2017
Messages
18
Office Version
  1. 365
Platform
  1. Windows
Hi, looking at historical stock data downloaded from Yahoo. It is basically 6 columns: Date, Open, High, Low, Close, AdjClose, Volume.

I am trying to Filter by the first date of the year and the last date of the year to get the Close. The issue I am having is that all the data is on working days, so it's not typically the 1st of the month. Actuallly, January 1st is always a holiday so it's the 2nd, 3rd or 4th of the month. Same with the last day day of the year, not all are the 31st and may even the last working day is the 28th of the month. I have used a formula to reduce it down by Filtering (using 365) for the DAY equal to or less than 3 and that helps, but want to clean it up to just the first working day of the year. Attached is an image of an example worksheet, but that formula is:

=FILTER(E:E,(MONTH(A:A)=1)*(DAY(A:A)<=3))

=FILTER(E:E,(MONTH(A:A)=1)*(DAY(A:A)=1),(DAY(A:A)=2))

=FILTER(E:E,(MONTH(A:A)=1)*(DAY(A:A)=2),(DAY(A:A)=3))

I have altered it to filter to the 2nd as well as the 3rd, as well as I have attempted multiple combined nested IF's, AND's and OR's without success to generate a single formula. Looking for any suggestions to what is likely a straight forward solution that I can no longer see. I've put those other formulas on the attached image.

I have tried multiple times but can not get 365 to allow me to let Xl2bb macros work even though MSFT trust center allows. It's loaded on my sheet so sorry, best I can do is an image of the start of the sheet. Understand, I am looking at 9347 rows of data, not just the few in the image.

Thanks!
 

Attachments

  • 2023-04-16_11-52-23.png
    2023-04-16_11-52-23.png
    103.6 KB · Views: 37

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I have tried multiple times but can not get 365 to allow me to let Xl2bb macros work
Have you checked under the general tab on the XL2BB file properties to make sure you haven't got an Unblock checkbox?
 
Upvote 0
Have you checked under the general tab on the XL2BB file properties to make sure you haven't got an Unblock checkbox?
Appreciate the idea, but no such luck. While I am sure it's something stupid I'm missing, I continue to miss the answer to XL2BB. I've disabled any and all blockers in Excel and Kaspersky. The program shows up on my workbook, but won't let me highlight nor capture any part of my sheet. "MiniSheet" and "Table Only" are grayed out. Thanks for the suggestion.
 
Upvote 0
As for your question try using the formulas below to determine the first/last days of the year. The N3 and N4 are only there for when Jan 1st isn't a weekend and really only applies to the first formula.

Book1.xlsb
BCDMN
31st day02/01/202301/01/2023
4Last day 29/12/202301/01/2024
Sheet1
Cell Formulas
RangeFormula
C3C3=WORKDAY(DATE(YEAR(TODAY()),1,1)-1,1,N3:N4)
C4C4=WORKDAY("1JAN"&(YEAR(TODAY())+1),-1,N3:N4)
 
Upvote 0
As for your question try using the formulas below to determine the first/last days of the year. The N3 and N4 are only there for when Jan 1st isn't a weekend and really only applies to the first formula.

Book1.xlsb
BCDMN
31st day02/01/202301/01/2023
4Last day 29/12/202301/01/2024
Sheet1
Cell Formulas
RangeFormula
C3C3=WORKDAY(DATE(YEAR(TODAY()),1,1)-1,1,N3:N4)
C4C4=WORKDAY("1JAN"&(YEAR(TODAY())+1),-1,N3:N4)

Thanks for the suggestion. Worked with it overnight and am unable to get it to work. Trying a few more things......
 
Upvote 0
Can you post your data using the boards XL2BB add-in so I can copy it and I'll have a look when I get in tonight
 
Upvote 0
Still can't get XL2BB to work on my desktop. I'll try my laptop in a bit to see if I can use it on it. Plus, have to thin out the database significantly by hand to make it work. Most of these databases are 9500 rows by 6 columns and the areas of interest are every 300 or so rows apart. I'll work on it.

Thank you for your efforts. Appreciated
 
Upvote 0
I don't need the full range, 20 rows will do as the layout is more important. Just needs enough to illustrate the issue
 
Upvote 0
Understood but the data points of interest are separated by 200+ rows so it works better to thin it out. Otherwise, there's one result at best!
 
Upvote 0
Here, finally

Sample File Filtering Dates.xlsx
ABCDEFGHIJKL
1OpenHighLowCloseAdj CloseVolume
212/26/19860.1714410.1727430.1710070.1710070.10669137152001/0/1900Close
312/29/19860.1710070.1727430.1640630.1640630.102359417024001/2/19870.1657990.165799
412/30/19860.1640630.1666670.1623260.1657990.103442254016001/4/19880.388889
512/31/19860.1657990.1701390.1657990.1675350.104525233568001/3/19890.372396**
61/2/19870.1675350.1692710.1649310.1657990.103442126432001/4/19890.376736
71/5/19870.1657990.1770830.1649310.1753470.109399484992001/0/19000
81/6/19870.1753470.1788190.1744790.1779510.111023400320001/0/19000
91/7/19870.1779510.18750.1779510.18750.116981609984001/0/19000
101/8/19870.1883680.1953130.1883680.1935760.120772614880001/0/19000
111/9/19870.1935760.2022570.1927080.2013890.125646637056001/0/19000
121/12/19870.2013890.2161460.1996530.214410.133771.29E+081/0/19000
1312/24/19870.3697920.3732640.3680560.3697920.230713126720001/0/19000
1412/28/19870.3680560.3697920.3472220.3559030.222047507168001/0/19000
1512/29/19870.3559030.3819440.3506940.3784720.236128794592001/0/19000
1612/30/19870.3784720.3888890.3767360.3871530.241544707040001/0/19000
1712/31/19870.3836810.3871530.3732640.3767360.235045615456001/0/19000
181/4/19880.3802080.3923610.3784720.3888890.2426271.1E+081/0/19000
191/5/19880.3975690.4027780.3923610.3958330.246961.56E+081/0/19000
201/6/19880.3975690.4149310.3958330.406250.2534591.22E+081/0/19000
211/7/19880.4027780.4210070.3993060.4201390.262124906768001/0/19000
221/8/19880.4184030.4288190.3862850.3888890.2426271.45E+081/0/19000
231/11/19880.3871530.4027780.3802080.401910.2507511.44E+081/0/19000
2412/22/19880.3645830.3680560.3593750.3611110.225297745920001/0/19000
2512/23/19880.3593750.3611110.3576390.3611110.225297171216001/0/19000
2612/27/19880.3611110.3645830.3593750.3593750.224213307728001/0/19000
2712/28/19880.3611110.3628470.3593750.3628470.22638212688001/0/19000
2812/29/19880.3611110.3715280.3611110.3697920.230713382752001/0/19000
2912/30/19880.3715280.3767360.3697920.3697920.230713638208001/0/19000
301/3/19890.3715280.3732640.3663190.3723960.232337518256001/0/19000
311/4/19890.3715280.3810760.3715280.3767360.235045538992001/0/19000
321/0/19000
Sheet1
Cell Formulas
RangeFormula
I2:I1048551I2=FILTER(A:A,(MONTH(A:A)=1)*(DAY(A:A)<=4),"")
J2:J1048551J2=FILTER(E:E,(MONTH(A:A)=1)*(DAY(A:A)<=4))
L3L3=FILTER(E:E,(MONTH(A:A)=1)*(DAY(A:A)=2),(DAY(A:A)=3))
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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