Results 1 to 5 of 5
  1. #1
    MikeEllis is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2015
    Posts
    5

    Date Selection Criteria

    Hi all,

    I have a big list of data, with a row of data for every day for each client.

    I need a selection criteria that will provide show the last day of the every month (historic data) for each client.

    I've had a go but I'm not making much progress.

    Any help would be appreciated.

    Thanks



    Michael

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Did you know that the 0 day of the month is the last day of the previous month?

  3. #3
    MikeEllis is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2015
    Posts
    5
    Quote Originally Posted by RuralGuy View Post
    Did you know that the 0 day of the month is the last day of the previous month?
    I did not know that, thanks!

    Although not quite figured it out yet. I have the below, but it is only showing the last day of last month, not the last day of every month.

    Day([ExtractDate])=Day(0)

    Any thoughts?

  4. #4
    MikeEllis is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2015
    Posts
    5
    Ok, it kind of works now...although I have noticed an issue.

    There is no data for weekends and public holidays!

    I dont think I can use the 0 day function as a result.

    Any thoughts on a work around?

    Thanks

  5. #5
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,841
    you can use a subquery

    Code:
    SELECT *
    FROM myTable
    WHERE ExtractDate=(SELECT Max(ExtractDate) FROM myTable AS T WHERE ClientID=myTable.ClientID AND Month(ExtractDate)=Month(Dateadd("m",-1,Date()))
    this will select from all dates in March if date is in April, from all years, but the max will be last month so will return the right result. You can play around with it if you want to get a set relating to last month only.

    Note, ensure your ExtractDate is indexed (I would expect it to be anyway). Using subqueries can have an effect on performance which is resolved by suitable indexing

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 04-02-2015, 12:45 PM
  2. Replies: 3
    Last Post: 08-21-2012, 03:05 PM
  3. Replies: 7
    Last Post: 04-30-2012, 10:52 AM
  4. Replies: 1
    Last Post: 02-09-2012, 11:33 PM
  5. Replies: 0
    Last Post: 02-09-2007, 09:20 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums