Last day of Month/Last Week of Month

G

Guest

Hello,

I have a bunch of tables that either have daily data (M-F) or weekly data
(usually Fridays) with a date field. I'd like to be able to pull this data
on different frequencies.

For example, for daily data, how can I get the last day of daily data on a
monthly or quarterly basis?
(I'm know that getting a particular day of week is easily solved with
Weekday () command)

Since my weekly data is from Friday's, I also need to get that last Friday
of a month or quarter.

I've seen some posts about getting a particular 3rd weekday of the month,
but I won't know whether the dates I have are the 3rd, 4th, etc of the month.

Your assistance and expertise are greatly appreciated.

Thank you.
kohai
 
D

David Seeto via AccessMonster.com

I would think that you could do this with a series of calculations - it's be
horrible if you tried to do it all int eh one formula, but not so bad if you
break it up into steps:

LastDayOfMonth:
DateSerial([Enter Year],[Enter Month]+1,1)-1

LastWeekDay
Weekday(LastDayOfMonth)

LastFriday:
iif(LastWeekDay>=6,LastDayOfMonth-(LastWeekDay-6),LastDayOfMonth-
(LastWeekDay+1))
 
M

Marshall Barton

David said:
I would think that you could do this with a series of calculations - it's be
horrible if you tried to do it all int eh one formula, but not so bad if you
break it up into steps:

LastDayOfMonth:
DateSerial([Enter Year],[Enter Month]+1,1)-1


More common is to use:
DateSerial([Enter Year],[Enter Month]+1,0)
 
G

Guest

Thank you both for your replys. However, I see that the code below will
transform all of the weekly dates to their end-of month date

1/5/90 becomes 1/31/90
1/12/90 " 1/31/90
1/19/90 " 1/31/90
1/26/90 " 1/31/90
2/2/90 " 2/28/90
etc .........
What I'm trying to do is pull only those records from 1/26/90, 2/23/90,
3/30/90 etc. These are the last weekly data points for each month.

I have the same situation with daily data, I'd like to get only the last
daily points for each month (or a quarter)

I apoligise if I did not properly phrase my original question.

Thank you.


Marshall Barton said:
David said:
I would think that you could do this with a series of calculations - it's be
horrible if you tried to do it all int eh one formula, but not so bad if you
break it up into steps:

LastDayOfMonth:
DateSerial([Enter Year],[Enter Month]+1,1)-1


More common is to use:
DateSerial([Enter Year],[Enter Month]+1,0)
 
D

David Seeto via AccessMonster.com

Well, you could build a separate table containing just those dates you're
interested in, and using a join to get to the data you want. This has the
down side of you having to add the required to this table every now and again.


The other thing you could do is build a query that applies the formula below
to your data table in a GROUP BY - this will give you all of the unique end
data values, and you can then use this query to join with your data table in
the same way that you would a stand alone table. The advantage of this
approach is that you don't have to maintain a separate table, since the query
is updated with the relevant end point as soon as the data table is updated.
The down side is that if your data table doesn't have records for the whole
month, that month won't appear at all in your output.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Week, monthly, quarterly 2
Month, DATE, Week 7
Previous Week, Month, year, etc. 2
week of the month 1
Display 4 weeks of data 10
Last full week 4
Select a day in a month 1
Pop message last businessday of month 3

Top