Results 1 to 10 of 10
  1. #1
    MrBologna is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    48

    Query sum returning wrong value

    I have a query that pulls data from 2 tables: Open_Items_List & Jobs_Parts.
    Open items is a table of all current PO's, with part numbers and quantity ordered. There may be duplicates in this table, so quantity ordered must be summed.
    Jobs_Parts is a table of the parts required for every active job in production.

    The final query must have the following fields:
    Qty_Needed : number of that part required: Comes from jobs_Parts
    Qty_Ready : number of those parts currently dedicated to that job: manually input
    Qty_still_needed: Qty_Needed - Qty_Ready (calculated field in jobs_Parts)


    Qty_On_Hand: the sum of all Qty_Ready
    Qty_On_Order: the sum of quantity ordered in Open_Items
    Qty_Short: (((sum of all Qty_Needed) - sum of all Qty_on_Hand) - Sum of qty_on_order)

    These sums should be specific to each part number, and show up for each item in Jobs_Parts.

    I started with trying to do it all in one step, but have now simplified to just getting part data.

    for better reference:

    The excel sheet I am attempting to duplicate:
    Click image for larger version. 

Name:	jobs inventroy screenie.jpg 
Views:	11 
Size:	36.3 KB 
ID:	36036

    The first query I have written to get data for each part (returning wrong values):
    Code:
    SELECT Open_Items_List.Part_No, Open_Items_List.Part_Description, Sum(Open_Items_List.Qty_Ordered) AS Qty_On_Order, Sum(Jobs_Parts.Qty_Ready) AS Qty_On_Hand, Sum(Jobs_Parts.Qty_Still_Needed) AS Qty_Short
    FROM Open_Items_List 
    INNER JOIN Jobs_Parts ON Open_Items_List.Part_No = Jobs_Parts.Part_No
    GROUP BY Open_Items_List.Part_No, Open_Items_List.Part_Description;

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    How is that returning the wrong values (what are the detail values, what is the sum, etc)? That should be the sum grouped by part and description. Can you attach a sample db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    MrBologna is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    48
    Here is how I tested that query:
    What was input:
    Click image for larger version. 

Name:	Capture.PNG 
Views:	10 
Size:	11.2 KB 
ID:	36037

    Click image for larger version. 

Name:	Capture3.PNG 
Views:	10 
Size:	7.9 KB 
ID:	36041

    What it returned:
    Click image for larger version. 

Name:	Capture1.PNG 
Views:	10 
Size:	4.6 KB 
ID:	36038

    And here it is further separated (not what I want, but may help diagnose):
    Click image for larger version. 

Name:	Capture2.PNG 
Views:	10 
Size:	6.4 KB 
ID:	36039


    I would like to see if I can resolve this quickly before I go through and take the time to make a sample database, as this database has a significant amount of private information.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    You've joined 2 tables there. Are there multiple records in both of them? The expectation would be that there is a single record in one, potentially multiple in the other.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    MrBologna is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    48
    Aaah okay, I separated it into 3 queries (2 to do sums and 1 to combine) and it seems to be working correctly now. Thank you!

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Glad you got it working.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    MrBologna is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    48
    However, now I cannot make edits to the Qty_Ready field now. I don't want to have to make that a popout edit window, as it's going to be the main feature of the form.
    Is it possible to make this do what I want it to? or will I have to separate them with a subdatasheet?
    I would rather avoid the latter, as opening and closing the expansion plus to find that info could get obnoxious when you're doing it constantly throughout each day.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Well, a totals query is read-only. You can't edit summed data, only the detailed data that makes it up. If you were able to edit summed data, which record(s) would it update?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    MrBologna is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    48
    The Qty_Ready field is not a summed field, it is an input field in Jobs_Parts.
    My final query basically displays the Jobs_Parts table, with the extra calculated fields stuck on the end.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Review http://allenbrowne.com/ser-61.html. Your query should hit one or more of this conditions.
    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. Replies: 2
    Last Post: 11-26-2014, 06:39 AM
  2. Forms - returning wrong value
    By Sheba in forum Forms
    Replies: 1
    Last Post: 11-12-2014, 02:02 PM
  3. Returning wrong items
    By cbende2 in forum Access
    Replies: 5
    Last Post: 08-01-2014, 07:43 AM
  4. Replies: 4
    Last Post: 06-12-2014, 07:01 AM
  5. DMax returning wrong value
    By nedbenj in forum Access
    Replies: 7
    Last Post: 10-24-2007, 10:30 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