Results 1 to 8 of 8
  1. #1
    chriswrcg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2018
    Location
    Usa
    Posts
    142

    query to sum field values based on another field

    On my task exceptions table I end up with multiple exceptions for each individual task. How can I sum all the exceptions times for task 1 only and ignore the rest.



    Here is my data after entering.
    Click image for larger version. 

Name:	18.JPG 
Views:	7 
Size:	36.0 KB 
ID:	35908

    The two fields I am interested in is Task# (blue Arrow) and Exception Duration (Red Arrow).
    Click image for larger version. 

Name:	20.jpg 
Views:	7 
Size:	54.8 KB 
ID:	35909

    I need a way to pull out all the duration's that happened during task 1 and add them together. (Red Box)
    and then do the same with task 2 (Green Box) and so on.
    Click image for larger version. 

Name:	19.jpg 
Views:	7 
Size:	55.1 KB 
ID:	35910
    The other problem is do I have to create this 15 times for the possible 15 task for the day Or is the a way to only pull out for the task that were completed?

  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
    Try this with the correct field names (inadvisable symbols and spaces will require field names be bracketed):

    SELECT TaskNum, Sum(Minutes) As TotalMinutes
    FROM TableName
    GROUP BY TaskNum
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    chriswrcg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2018
    Location
    Usa
    Posts
    142
    you want me to build a query or a report with an expression?

    I know how to calculate the sum of a column of fields by creating a control source in a report I just don't know how to seperate the total based on task #.
    Click image for larger version. 

Name:	21.JPG 
Views:	4 
Size:	99.4 KB 
ID:	35911

  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
    That's a query, which could be the source of a report.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    chriswrcg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2018
    Location
    Usa
    Posts
    142
    I don't know how to turn this into a query.
    SELECT TaskNum, Sum(Minutes) As TotalMinutes
    FROM TableName
    GROUP BY TaskNum
    Click image for larger version. 

Name:	22.JPG 
Views:	4 
Size:	43.0 KB 
ID:	35912

  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
    Eliminate the third column. Click on the Totals icon on the ribbon. On the duration field, change Group By to Sum. Run the query.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    chriswrcg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2018
    Location
    Usa
    Posts
    142
    Thank you. That was amazingly simple. I always make things harder than they need to be.

  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
    No problem. If you switch that to SQL view now, it should resemble what I posted earlier. A lot of times on the forum you'll see people posting SQL, which you can enter/edit directly in SQL view. The design view you posted a picture of is just a GUI that creates SQL, which is what's actually used behind the scenes.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 1
    Last Post: 06-01-2017, 09:29 AM
  2. Replies: 2
    Last Post: 05-17-2017, 06:17 AM
  3. Replies: 7
    Last Post: 06-03-2015, 11:42 AM
  4. Replies: 2
    Last Post: 11-30-2014, 07:52 AM
  5. Replies: 1
    Last Post: 02-19-2014, 11:07 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