Results 1 to 5 of 5
  1. #1
    tiredhero16 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2018
    Posts
    3

    Totals question

    Say I have a table with the product ID and product category, and units in stock. I would like for each individual unit to grouped so that access displays the total number of products in each category. I have been at this for awhile, and I am not having any luck.



    Click image for larger version. 

Name:	clayborne.PNG 
Views:	7 
Size:	24.0 KB 
ID:	32706

    I would like the total number of products per each category (ex. Windchimes-4, Birdhouses-3)

    Thank you so much in advance.
    Attached Thumbnails Attached Thumbnails heye.PNG  

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,976
    Replace TableName with whatever your table is called
    Check I've got the field names correct

    Code:
    SELECT TableName.[Product Category], Count(TableName.[Product Category]) AS [Total Products]
    FROM TableName
    GROUP BY TableName.[Product Category], TableName.[Units in Stock]
    ORDER BY TableName.[Product Category];
    Recommend you do not use spaces in field or table names - then the [] brackets wouldn't be needed
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    tiredhero16 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2018
    Posts
    3
    My mistake for not being very clear. What I intended to say was that I am trying to sort by how many items per category are not in stock (0). I think that is easier than the SQL code you provided, but I still can't figure it out.

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,976
    Slightly confused as I got a notification email saying:
    That works! Thanks!
    Assume you edited that afterwards....

    Quote Originally Posted by tiredhero16 View Post
    My mistake for not being very clear. What I intended to say was that I am trying to sort by how many items per category are not in stock (0). I think that is easier than the SQL code you provided, but I still can't figure it out.
    I think you mean COUNT items WHERE not in stock i.e. Units in Stock = 0
    Code:
    SELECT Count(TableName.[Product Category]) AS [Total Products]
    FROM TableName
    WHERE TableName.[Units in Stock] = 0;
    For the data shown, this gives Total Products = 8

    If you want GROUPING as well
    Code:
    SELECT TableName.[Product Category], Count(TableName.[Product Category]) AS [Total Products]
    FROM TableName
    WHERE TableName.[Units in Stock] = 0
    GROUP BY TableName.[Product Category]
    ORDER BY TableName.[Product Category];
    This gives Birdhouses = 3 ; Planters = 1 ; Windchimes = 4
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    tiredhero16 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2018
    Posts
    3
    Great. This time I got it. No edits this time. Thanks!

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

Similar Threads

  1. Query detail totals vs. Summary Totals do not match?
    By aellistechsupport in forum Queries
    Replies: 9
    Last Post: 01-15-2016, 11:36 AM
  2. General totals question
    By brownk in forum Database Design
    Replies: 8
    Last Post: 05-18-2012, 09:16 AM
  3. Replies: 5
    Last Post: 12-06-2011, 11:18 AM
  4. Month totals and Year totals
    By marksnwv in forum Access
    Replies: 1
    Last Post: 08-05-2011, 10:13 AM
  5. Calculated and send to totals. Question
    By castellano in forum Programming
    Replies: 1
    Last Post: 06-12-2009, 12:40 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