Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2012
    Posts
    16

    How to get percentages and numerical values in the same query

    I have a list of things, where each thing can be classified into 3 different classicifications. I want to count how many classifications of each thing there are in my list as well as see what percentage these classifications make up in my list. Only issue is, I have no idea how to work this into a query. I can get a numerical list just fine, but when it comes to percentages, it seems like rocket science.

    Let's say I have a table like this.

    Entry, Classification
    1, A
    2, A
    3, B
    4, C
    5, B
    6, B
    7, A
    8, B

    So there are 3 A's, 4 B's, and 1 C. I want to produce a query that counts how many there are, and what percentage they make up. I want to make a query that looks like this:

    A....3.....37.5%


    B....4......50.0%
    C....1......12.5%

    Should be pretty simple, no? Yet I can't figure it out. I always get errors. For one thing, I don't even know how to use the "CountOf [Field]" in differnet fields.

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    I create a Table6 like your example.

    Then I created a query [Query11] to count all the records in the table:
    Code:
    SELECT Count(*) AS TotalEntries
    FROM Table6;
    Then a second [Query12] like this:
    Code:
    SELECT Table6.Classification, Count(Table6.Classification) AS CountClass, Avg(Query11.TotalEntries) AS TotEntries
    FROM Table6, Query11
    GROUP BY Table6.Classification;
    Then a third Query like this:
    Code:
    SELECT Query12.Classification, Query12.CountClass, Query12.TotEntries, ([CountClass]/[TotEntries])*100 AS PercentEntries
    FROM Query12;
    See screenshot for final result of the three queries.

    Hope this helps!

    P.S. - there may be a one-step solution . . .
    Attached Thumbnails Attached Thumbnails Percent.JPG  

  3. #3
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    This combines steps 1 & 2:
    Code:
    SELECT Table6.Classification, Count(Table6.Classification) AS TotalForClass, Avg((Select Count(*)
    From Table6 As A
    )) AS TotalRecs
    FROM Table6
    GROUP BY Table6.Classification;
    There is probably a way to get the percentage into this as well . . .

  4. #4
    Join Date
    Apr 2012
    Posts
    16
    damn I thought I could just do it in one query. Thanks all for your help though, got it to work

  5. #5
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    I think there could be a way to get it all into one query - I'll see if I can get one of the experts to look at this.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    This will probably be easier with a report where you can take advantage of report Grouping & Sorting and summary calcs in headers/footers instead of trying to do all in query.
    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.

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

Similar Threads

  1. Replies: 1
    Last Post: 03-04-2012, 11:22 AM
  2. Query Numerical and Text
    By Athyne in forum Queries
    Replies: 1
    Last Post: 01-14-2012, 12:07 AM
  3. Replies: 3
    Last Post: 11-15-2011, 02:41 PM
  4. Rounding Problem With Percentages
    By Lady_Jane in forum Queries
    Replies: 5
    Last Post: 09-01-2011, 02:32 PM
  5. How To Compute Percentages
    By zephaneas in forum Queries
    Replies: 7
    Last Post: 06-20-2011, 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