Results 1 to 5 of 5
  1. #1
    BLD21 is offline Advanced Beginner
    Windows 2K Access 2007
    Join Date
    Apr 2011
    Posts
    55

    Max Date Function Not Working

    I am having a problem trying to get the MAX date function to work properly. I am starting with the following query:


    SELECT DISTINCT [ADP - WIP Audit 05112017 use].[Associate ID], report_Recurring_Comp.[Pay Component], report_Recurring_Comp.[Event Date] INTO 1
    FROM [ADP - WIP Audit 05112017 use] INNER JOIN report_Recurring_Comp ON [ADP - WIP Audit 05112017 use].[Associate ID] = report_Recurring_Comp.[Person Id]
    WHERE ((([ADP - WIP Audit 05112017 use].[Associate ID])=47291));

    results are:
    Associate ID Pay Component Event Date
    47291 PC000071-US Wireless Phone 75 8/1/2016
    47291 PC000071-US Wireless Phone 75 1/2/2017
    47291 PC000071-US Wireless Phone 75 5/8/2017
    47291 S-Base Salary 7/31/2016
    47291 S-Base Salary 8/1/2016
    47291 S-Base Salary 1/2/2017
    47291 S-Base Salary 5/8/2017


    I now add max date to event date field:
    SELECT DISTINCT [ADP - WIP Audit 05112017 use].[Associate ID], report_Recurring_Comp.[Pay Component], Max(report_Recurring_Comp.[Event Date]) AS [MaxOfEvent Date] INTO 1
    FROM [ADP - WIP Audit 05112017 use] INNER JOIN report_Recurring_Comp ON [ADP - WIP Audit 05112017 use].[Associate ID] = report_Recurring_Comp.[Person Id]
    GROUP BY [ADP - WIP Audit 05112017 use].[Associate ID], report_Recurring_Comp.[Pay Component]
    HAVING ((([ADP - WIP Audit 05112017 use].[Associate ID])=47291));

    Results:
    Associate ID Pay Component MaxOfEvent Date
    47291 PC000071-US Wireless Phone 75 5/8/2017
    47291 S-Base Salary 5/8/2017


    good so far, but when I add the amount field all dates come back:
    SELECT DISTINCT [ADP - WIP Audit 05112017 use].[Associate ID], report_Recurring_Comp.[Pay Component], Max(report_Recurring_Comp.[Event Date]) AS [MaxOfEvent Date], report_Recurring_Comp.Amount INTO 1
    FROM [ADP - WIP Audit 05112017 use] INNER JOIN report_Recurring_Comp ON [ADP - WIP Audit 05112017 use].[Associate ID] = report_Recurring_Comp.[Person Id]
    GROUP BY [ADP - WIP Audit 05112017 use].[Associate ID], report_Recurring_Comp.[Pay Component], report_Recurring_Comp.Amount
    HAVING ((([ADP - WIP Audit 05112017 use].[Associate ID])=47291));

    results:
    Associate ID Pay Component MaxOfEvent Date Amount
    47291 PC000071-US Wireless Phone 75 5/8/2017 75
    47291 S-Base Salary 8/1/2016 3276.08
    47291 S-Base Salary 1/2/2017 3339.54
    47291 S-Base Salary 5/8/2017 3426.37
    47291 S-Base Salary 5/8/2017 3846.16


    any help is greatly appreciated!
    Bruce

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,523
    MAX (or min) only works with 2 fields. Otherwise you get the MAX involving 3 fields, and it is not max anymore.
    you want the max(field) and the ID. Then use the ID to grab the record.

    Q1: select ID, MAX(field) from table
    Q2: select * from table where Q1.ID = table.ID

  3. #3
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    You could try changing the Group By on the amount to First.

  4. #4
    BLD21 is offline Advanced Beginner
    Windows 2K Access 2007
    Join Date
    Apr 2011
    Posts
    55
    Thanks for responding, I forgot to clarify I need the max date within each Pay Component. There could be multiple pay components and I need to see just the max date for each.

  5. #5
    BLD21 is offline Advanced Beginner
    Windows 2K Access 2007
    Join Date
    Apr 2011
    Posts
    55
    It looks like Group By on the amount to First will work.

    Thanks aytee111 and ranman256.

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

Similar Threads

  1. Date() function not working in query
    By riggsdp in forum Queries
    Replies: 8
    Last Post: 02-05-2015, 02:33 PM
  2. Date add function not working in some cases.
    By behnam in forum Programming
    Replies: 3
    Last Post: 08-25-2014, 10:39 AM
  3. Replies: 3
    Last Post: 01-29-2013, 04:34 AM
  4. Max Function Not Working With Date
    By cec in forum Forms
    Replies: 4
    Last Post: 11-14-2012, 06:00 PM
  5. NZ() function not working?
    By EvanRosenlieb in forum Programming
    Replies: 6
    Last Post: 12-22-2011, 05:37 PM

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