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

    maxDate sum

    I have an inventory table with products, dateOfCount, and Qty.


    If this is the input:
    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
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Could try a TOP N nested subquery. Review: http://allenbrowne.com/subquery-01.html#TopN
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76
    I went through your link but I couldn't get the concepts to work for me.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Try:

    SELECT * FROM Inventory WHERE Product & ":" & DateOfCount IN (SELECT TOP 1 Product & ":" & DateOfCount FROM Inventory AS Dupe WHERE Dupe.Product=Inventory.Product ORDER BY Dupe.DateOfCount DESC, Dupe.Product DESC);

    or

    SELECT Inventory.Product, Inventory.DateOfCount, Sum(Inventory.Qty) AS SumOfQty
    FROM Inventory
    GROUP BY Inventory.Product, Inventory.DateOfCount, [Product] & ":" & [DateOfCount]
    HAVING ((([Product] & ":" & [DateOfCount]) In (SELECT TOP 1 Product & ":" & DateOfCount FROM Inventory AS Dupe WHERE Dupe.Product=Inventory.Product ORDER BY Dupe.DateOfCount DESC, Dupe.Product DESC)));
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. MaxDate From Query
    By Mpike926 in forum Access
    Replies: 4
    Last Post: 01-28-2015, 08:33 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