Results 1 to 4 of 4
  1. #1
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76

    sum if max date

    I have a table that stores a physical inventory count. I am struggling to write a query that will sum the quantity of just the records with the most recent date. For example:
    If this is the input, Product, Date, and Qty.
    product1 6/1/2015 1
    product1 6/1/2015 1
    product1 5/1/2015 1



    I want a query to sum the qty of only the MaxDate, so in the example I gave, the total Qty would be 2.
    Currently I can output the max date just fine, but when I sum the Qty I keep getting 3 as my output.

    Thanks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    In a query, Q1, get max of date:
    select Max([date]) as MaxOfDate from table.

    In another query, Q2, use Q1 to limit the list of Q2...
    SELECT * FROM table INNER JOIN qsMaxDate ON table.DAte = qsMaxDate.MaxOfDAte

  3. #3
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76
    Thanks for the post, but I am still having an issue.
    a proposal of the issue is that in Q1, get max of date, it only returns 1 instance of the product even if it was counted two times on the same day.
    I checked all levels of the date format field and the Time is not being captured. The date field is set to Date/Time as a dataType but then the format is Short Date.
    here is my Q1:

    SELECT [Tble Inventory].ProductCode, Max([Tble Inventory].dateCounted) AS MaxOfDate
    FROM [Tble Inventory]
    GROUP BY [Tble Inventory].ProductCode;

    Q2:
    SELECT *
    FROM [Tble Inventory] INNER JOIN Qry_MaxDateInventory ON [tble Inventory].DateCounted = qry_MaxDateInventory.MaxOfDate;



    Thanks.

  4. #4
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76
    Does anybody have a suggestion on how to handle this issue? It is a real thorn in my side.
    Thanks.

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

Similar Threads

  1. Replies: 11
    Last Post: 06-28-2015, 06:42 PM
  2. Replies: 7
    Last Post: 12-26-2014, 12:17 PM
  3. Replies: 3
    Last Post: 12-02-2014, 07:58 PM
  4. Replies: 11
    Last Post: 07-20-2014, 06:22 PM
  5. Replies: 3
    Last Post: 08-21-2012, 03:05 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