Results 1 to 6 of 6
  1. #1
    mattshank is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    7

    Sum specific field where records have the same product ID

    I'm new to Access and SQL queries in general. I have a table of job tickets with fields for Job#, Product#, and number of products sold. I want to create a monthly stock summary. So I want to create a report that lists ever product sold and the total number of each product sold. Right now, it pulls each record from the Job tickets table and, as a result, displays records with the same product number multiple times. I want to add up the number sold of records that have the same product number.



    My thinking is that I could make a query that selects records from the Job tickets table with distinct product numbers. Then loop through each product number in that recordset and run a query for each product number to add up the total number sold, but that seems like a lot of querying to me. Is there another way to do this?

  2. #2
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Here are a few examples: I assume Product Number is text, if not then use whatever product number you want in your query.
    Products Sold > 0
    Product Number "Apples"
    However; if you want all of this in a Report, you need to use a different approach and Group By for each Product, etc...
    Not really sure of your db structure, you should have a separate table for products.

    With more info, maybe we can advise further.

    HTH

  3. #3
    mattshank is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    7
    I do have a separate table for products and product number is a string. But your example will only find me the number of records for one product. And it won't add the number sold for each record that has "Apple" as the product number.

    I have a table that has all the products from certain jobs with fields (JobID, ProductNo, NumberSold), where JobID and ProductNo are the primary key. What I want is a report that disregards JobNo, lists all the products sold only once, and shows the total number of each product sold, regardless of whether they were sold in different jobs (JobID).

  4. #4
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    So, does your query show the desired results? If not, can you post a screenshot of the query? If it does return the desired results, then create a report based on that query and group by productNo. NumberSold <2

    HTH

  5. #5
    mattshank is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    7
    I am slightly confused. As my query currently is, it shows the ProductNo. and the the NumberSold, but it shows duplicate ProductNo.s, while I want it to add up the NumberSold values.

    Click image for larger version. 

Name:	query.PNG 
Views:	5 
Size:	11.8 KB 
ID:	18060
    This picture shows what my query churns out. As you can see, it shows two records with the same ProductNo. I'd like there to be only one record that has a total NumberSold of 23. And I want the query to work with infinite duplicate ProductNo.s.

  6. #6
    mattshank is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    7
    I think I figured it out. I grouped by ProductNo. by clicking the "Totals" button the Query Design toolbar. Then in the "Total:" row under NumberSold in Design View, I selected "Sum". It seems to do what I want it to do.

    This is the SQL view of the query I believe is doing what I want to do:
    SELECT tblJobStockItem.CatDeptItemNo, Sum(tblJobStockItem.NumberSold) AS SumOfNumberSold, tblMstrStockList.ValuePerItem, tblMstrStockList.ItemMultiplier
    FROM tblMstrStockList INNER JOIN (tblJob INNER JOIN tblJobStockItem ON tblJob.JobNo = tblJobStockItem.JobNo) ON tblMstrStockList.CatDeptItemNo = tblJobStockItem.CatDeptItemNo
    GROUP BY tblJobStockItem.CatDeptItemNo, tblMstrStockList.ValuePerItem, tblMstrStockList.ItemMultiplier, tblJob.DateCreated
    ORDER BY tblJobStockItem.CatDeptItemNo;

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

Similar Threads

  1. Replies: 12
    Last Post: 02-25-2014, 08:32 AM
  2. Replies: 11
    Last Post: 10-15-2013, 05:59 PM
  3. Replies: 5
    Last Post: 05-22-2013, 12:38 PM
  4. Replies: 1
    Last Post: 04-04-2013, 11:59 AM
  5. Replies: 2
    Last Post: 02-22-2012, 02:36 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