Results 1 to 6 of 6
  1. #1
    DaveT99 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    76

    Find annual totak issues per year from a table of transactionsr

    Is there a better way



    I was given a spare parts dataset with 3 columns, Stock No, Date Issued and Qty issued for 2017, 2018 & 2019

    The aim was to obtain the usage for each year for each spare

    I achieved, but usng a long winded approach i.e. over 4 steps

    Step 1 I created a new column called YEAR, and I ran 3 separate select queries to assign the year in the new column for each issue (transaction)

    Step 2 I created a cross tab query to see the quantity for each year

    Step 3 I converted the cross tab query output into table, using a make table query

    Step 4 I then linked the quantity per year table (new) with a 2nd table containing other data like unit price, etc

    Can anyone suggest if this process can be streamlined a little

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Do you really want the CROSSTAB display?

    Why would you need 3 queries to assign year to new column?

    Steps 1 and 2 might be done in a single query.

    A CROSSTAB query can join to other tables/query so Step 3 might not be needed.

    Perhaps you should provide sample data. If you want to provide db for analysis, follow instructions at bottom of my post.
    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.

  3. #3
    DaveT99 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    76

    Streamline process

    Not sure if I have done this correct, but thanks for such a quick reply
    Please access file as a zip
    Thanks again
    Dave
    Attached Files Attached Files

  4. #4
    DaveT99 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    76

    screen shots

    have attached a word doc with examples of what I did
    Attached Files Attached Files

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Year is a reserved word (it is a function). Should not use reserved words as names for anything.

    A simple aggregate query will sum the Qty field by year for each part:

    SELECT tbl_Issues.Stock_No, Year([Issue_Date]) AS Yr, Sum(tbl_Issues.Qty) AS SumOfQty, Avg(tbl_Issues.Unit_Cost) AS AvgUnitCost
    FROM tbl_Issues
    GROUP BY tbl_Issues.Stock_No, Year([Issue_Date]);

    If you want to pivot the data so each year is a column header:

    TRANSFORM Sum(tbl_Issues.Qty) AS SumOfQty
    SELECT tbl_Issues.Stock_No
    FROM tbl_Issues
    GROUP BY tbl_Issues.Stock_No
    PIVOT Year([Issue_Date]);

    More info about CROSSTAB http://allenbrowne.com/ser-67.html

    Use the query design tools on the ribbon.

    If this is not what you want, then provide sample of desired output.

    There is only 1 table in the posted db.
    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.

  6. #6
    DaveT99 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    76
    Thanks you so very very much June7, for such a quick response. Your solutions have exteded my Access knowledge, especially the use of the expression Yr: Year([Issue_Date])
    Sorry forgot to include the tble SPD1, but you have given me two perfect solutions
    Dave

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

Similar Threads

  1. Replies: 8
    Last Post: 04-03-2018, 03:41 PM
  2. Replies: 19
    Last Post: 01-24-2016, 07:48 PM
  3. Query to find the second largest year
    By hawkins in forum Queries
    Replies: 2
    Last Post: 07-05-2011, 11:17 AM
  4. Query can't find Year data
    By G.King in forum Queries
    Replies: 7
    Last Post: 06-23-2011, 03:07 PM
  5. find the closest year
    By 12345678 in forum Queries
    Replies: 1
    Last Post: 05-25-2011, 05: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