Results 1 to 7 of 7
  1. #1
    justtrentjohnson is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Aug 2014
    Posts
    4

    Latest Date/Project Query

    Hello all,



    I am attempting to build a query that Selects the latest date from Each project I have listed. Here's an example:

    What I have:
    Project 1 (date)
    Project 1 (date)
    Project 2 (date)
    Project 3 (date)

    What I want:
    Project 1 (Latest Date)
    Project 2 (Latest Date)
    Project 3 (Latest Date)

    How would I start?

  2. #2
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    You could use a query with the "Totals" option. In the Total row, select "group by" for all the fields except the date; for that one you would select "Max".

    When you run the query, you will get the maximum (latest) date for each project. In order for this to give you exactly what you want, you have to be sure that the columns you select have the same data for each project, except for the date, otherwise you won't get one line per project.

    John

  3. #3
    justtrentjohnson is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Aug 2014
    Posts
    4
    John,
    The columns are not the same data. The logical format of the table is

    TABLE{Project,Task,DateCompleted}

    I can get the query down to:
    Project | MAX(DateCompleted)

    However, I want the output to be The project, the latest date, and the task associated with that project/date, however I can't include task in the aggregate function because if I do, Project+Task are mostly unique, and I get a data dump.

    I have a feeling I'll need to implement a subquery, however I'm having a hard time pinpointing how to do it.

  4. #4
    SMC's Avatar
    SMC is offline Master Ninja
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Columbus, OH
    Posts
    28

  5. #5
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    There are other ways, but here's what I would do:

    Once you have your project/max date query, create another new query.

    In the new query, include the first query and the original table. Join these two on Project number and date.

    When you run it, the task will now be the task associated with the latest date.

    John

  6. #6
    justtrentjohnson is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Aug 2014
    Posts
    4
    After setting up the relationship with the Table and Query, I've gotten a even larger data dump consisting of multiple entries repeated. Attached is the SQL for both steps:

    Step 1:
    SELECT [Tasks Performed].Project, Max([Tasks Performed].DateCompleted) AS MaxOfDateCompleted
    FROM [Tasks Performed]
    GROUP BY [Tasks Performed].Project;
    {This outputs all Projects and the last date something was done}

    Step 2:
    SELECT [Tasks Performed].*
    FROM [Tasks Performed] INNER JOIN [Step 1] ON ([Tasks Performed].DateCompleted = [Step 1].MaxOfDateCompleted) AND ([Tasks Performed].Project = [Step 1].Project);

    This produces a ton of unusuable data.
    Last edited by justtrentjohnson; 08-11-2014 at 11:42 AM. Reason: Removed [Tasks Performed].Task from Step 1.

  7. #7
    justtrentjohnson is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Aug 2014
    Posts
    4
    UPDATE:
    It works now. For some reason it didn't before, but now it does. Thank you!

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

Similar Threads

  1. Query: select latest date within given category
    By martinhough in forum Queries
    Replies: 4
    Last Post: 10-22-2013, 12:34 PM
  2. Query to Extract records with latest date
    By rkalapura in forum Queries
    Replies: 2
    Last Post: 03-13-2013, 05:48 AM
  3. Replies: 7
    Last Post: 11-29-2012, 11:36 AM
  4. Query for latest date? what am I doing wrong?
    By Overdive in forum Queries
    Replies: 1
    Last Post: 12-18-2009, 06:04 AM
  5. Query to find latest date
    By Lockrin in forum Access
    Replies: 2
    Last Post: 12-16-2009, 10:00 AM

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