Results 1 to 5 of 5
  1. #1
    bbdsbd is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    4

    Counting stock used? From sales data

    Hi

    I am new to this Forum and to Access, But have a fair bit of excel knowledge.
    I am currently moving away from Excel and wanting similar results in Access.

    I am creating a stock sold count and got stuck already.

    On a basic Level I have…

    “PRODUCT” table with the Header “CODE”


    =Each Row is product info by code

    “SALES” table with “DATE” & “PRODUCT CODE”
    =Each Row is a dated Sale with Product code.


    What I am trying to see…

    I want to be able to see TOTAL of each product sold at this stage (all dates).

    I don’t think you can calculate this on the product table as simple as creating a USED column as a calculated field.
    But in my Language (not access / SQL) I think I would do something like…

    “Count occurrence (PRODUCTS.CODE) in (SALES.PRODUCT CODE)”

    So just seeking some advice to which way to go about this.

    I have Google'd and searched, but kept hitting brick walls, or felt there was an easier solution than the 5 queries linking back and forth some web pages explained.

    Thank you
    Ste

  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,840
    depends on the context but in Access it would be

    Code:
    SELECT [Product Code], count(*) AS Occurrences 
    FROM SALES
    GROUP BY [Product Code]
    which will provide the data for all products sold

    or if you wanted to work it off the product table so you could see 0 sales for products not sold

    Code:
    SELECT Code, T.Occurrences
    FROM PRODUCT LEFT JOIN
        (SELECT [Product Code], count(*) AS Occurrences 
         FROM SALES
         GROUP BY [Product Code]) AS T
    ON Product.Code=T.[Product Code]

  3. #3
    bbdsbd is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    4
    Thanks Ajax...But I am going to sound stupid here...
    Where do I put this code?

  4. #4
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,840
    It is a complete query - click on Create>Query Design

    Then close the showtable widnow as it is not required

    Then click on the SQL view (top left) and past the code

    You will need to change the names of fields and tables to what you are actually using

    I don’t think you can calculate this on the product table as simple as creating a USED column as a calculated field
    You can't. Calculated fields are generally very limited (data changes may not be reflected in the calculation and values cannot be indexed for example), and anyway they cannot reference data in another table

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848

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

Similar Threads

  1. Replies: 2
    Last Post: 09-16-2014, 02:25 PM
  2. Replies: 1
    Last Post: 01-10-2014, 12:00 AM
  3. Replies: 0
    Last Post: 12-13-2012, 03:18 AM
  4. Comparing Two years of Sales Data
    By Eric@Gopher in forum Programming
    Replies: 2
    Last Post: 08-07-2012, 12:17 PM
  5. Replies: 5
    Last Post: 06-30-2011, 02:24 AM

Tags for this Thread

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