Page 1 of 2 12 LastLast
Results 1 to 15 of 29
  1. #1
    roar58 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2012
    Location
    Kristiansand, Norway
    Posts
    32

    Item in the query as a percentage of a total

    Hi!


    I work in a business manager at a school. In an Excel worksheet this table is easy to create, but how do I do it in Access? 3 students participate in a group. In the input field I type number of hours they use in the group. In an Access query, is there a way to get the percentage of each student of the total number of hours?

    Group 1 Number of hours Percentage
    Student 1 7 58,33 %
    Student 2 3 25,00 %
    Student 3 2 16,67 %
    Total 12 100,00 %

    Greetings, roar58

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Assume a table structure like:
    Group Student NumHours
    1 1 7
    1 2 3
    1 3 2

    Try this query:
    SELECT Group, Student, Sum(NumHours) AS SumOfNumHours, (SELECT Sum(NumHours) As GroupHrs FROM Table1 GROUP BY Group) AS TotGroup, Sum([NumHours]/[TotGroup]) AS Pct
    FROM Table1
    GROUP BY Group, Student;
    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
    roar58 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2012
    Location
    Kristiansand, Norway
    Posts
    32
    Hi! Thank you, June7, for a very quick reply!
    I have tried the query - and it does indeed function. Hope it will also function when I shall install it in a complex database structure.
    I have never been using the forum before and this was indeed a very useful way to solve a problem I couldn't sort out myself. So again, thanks a lot!
    Greetings from Roar58.

  4. #4
    roar58 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2012
    Location
    Kristiansand, Norway
    Posts
    32
    Hi! I have worked with it, and seen that I have a need for a slightly more advanced query. The last query had only one group as an option. Now I want a query with more groups, so that I can get the result below. Anyone who can help me making such a query - or do I have to solve the problems within "Forms"?

    Group Student Number of Hours Percentage
    1 1 7 58,33 %
    1 2 3 25,00 %
    1 3 2 16,67 %
    Total 12 100,00 %
    2 1 10 11,76 %
    2 2 20 23,53 %
    2 3 15 17,65 %
    2 4 40 47,06 %
    Total 85 100,00 %

    and so forth....

    Greetings from Roar58

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Build a report and use its Grouping and Sorting with aggregate calcs functionality. Use the same query as RecordSource for the report.
    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
    roar58 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2012
    Location
    Kristiansand, Norway
    Posts
    32

    Enter data for another group

    Forgive me, June7, for my relatively small knowledge in queries. The query doesn't function if I enter datas of one more group (Group 2). I guess this won't help if make a report (which I have tried) - I guess the source of the report must be a query that can function. Any way to do this? I can make several queries and several reports, one for each group, but this doesn't look very elegant? Thankful for your advice!



    Quote Originally Posted by June7 View Post
    Assume a table structure like:
    Group Student NumHours
    1 1 7
    1 2 3
    1 3 2

    Try this query:
    SELECT Group, Student, Sum(NumHours) AS SumOfNumHours, (SELECT Sum(NumHours) As GroupHrs FROM Table1 GROUP BY Group) AS TotGroup, Sum([NumHours]/[TotGroup]) AS Pct
    FROM Table1
    GROUP BY Group, Student;

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Attached is example with report Grouping & Sorting and aggregate calcs. EDIT: Purpose served, file removed.

    Will there be multiple records for each student in a group?
    Last edited by June7; 03-03-2012 at 02:08 PM.
    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.

  8. #8
    roar58 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2012
    Location
    Kristiansand, Norway
    Posts
    32
    No, there will be just one record for each student in a group, so your report fits perfect - as I can see now. I have been working with Access for some years, but I have always produced reports with Queries as the source. Now I learned that I can also do it more directly from a table.
    Thanks a lot, again!

  9. #9
    roar58 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2012
    Location
    Kristiansand, Norway
    Posts
    32
    Hi again June7!
    I do still have some problems when transferring some fields into my own database.
    In your report there is a field named [GroupTotal] which is defined as Sum (NumHours) at group level.
    But where is this field defined? I cannot find it's definition. When I go to my own report I don't succeed in defining this field.

    Greetings from Roar58

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    It is not a field, it is name of textbox.
    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.

  11. #11
    roar58 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2012
    Location
    Kristiansand, Norway
    Posts
    32
    Thank you again! This was very helpful after having seached for a field for some hours - the solution came in your one-liner! Greetings from Roar58

  12. #12
    roar58 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2012
    Location
    Kristiansand, Norway
    Posts
    32
    Hi again!
    My project is extended day by day when I get back to the end users of the report. Now I have this report I would like to produce:
    Group Students City NumHours Percentage MaxHours ShareHours
    1 1 Oslo 7 58,33 % 4,08
    1 2 Bergen 3 25,00 % 1,75
    1 3 Bergen 2 16,67 % 1,17
    Total 12 100,00 % 7 7,00
    2 1 Oslo 10 11,76 % 4,71
    2 2 Bergen 20 23,53 % 9,41
    2 3 Oslo 15 17,65 % 7,06
    2 4 Bergen 40 47,06 % 18,82
    Total 85 100,00 % 40 40,00
    Total report 47,00
    Sum Oslo 15,85
    Sum Bergen 31,15
    Total 47,00

    The last things that happened to the report was this: The percentages should calculate a share of the max amount of hours per group. To produce the share amounts of hours I have made. But it's harder to summarize what is text boxes and not fields - the far right column. Is there a way to summarize these text boxes and to make the sums "7,00" and "40,00". I get error message when I try =Sum ([TextBox18])

    The students come from various cities (the two biggest cities in Norway). In the end of the report I also want to summarize the hours per city. I have tried a select sentence, but here also I think there is problems because I want to summarize a text box and not a field. Any way to solve this?

    Greetings from Roar58

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    See if this version is getting there. Are there only two cities in the data? If you want a lot more than two cities in the report totals, consider a subreport. EDIT: Purpose served, file removed.
    Last edited by June7; 03-07-2012 at 01:38 PM.
    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.

  14. #14
    roar58 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2012
    Location
    Kristiansand, Norway
    Posts
    32

    Smile

    Quote Originally Posted by June7 View Post
    See if this version is getting there. Are there only two cities in the data? If you want a lot more than two cities in the report totals, consider a subreport.
    Thank you again. It helps a lot! There are at least four cities, so I consider your proposal. I have never worked with subreports before, so I guess I have to read something about them then. My colleagues are very enthusiastic over the database with these new possibillities and and will transform their working situation a lot for the better!

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    If only 4 or 5 cities would not be so bad to use the method shown in sample. But would have to modify report each time a city added, if that is possibility. Good luck!
    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.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 10-25-2011, 08:32 PM
  2. Creating a percentage of total records report
    By sai_rlaf in forum Reports
    Replies: 3
    Last Post: 08-12-2011, 11:39 AM
  3. Percentage Calculation in a Query
    By Lynn in forum Queries
    Replies: 1
    Last Post: 07-16-2010, 11:23 PM
  4. Last matched item in an unmatching query
    By kabaa01 in forum Queries
    Replies: 0
    Last Post: 05-19-2010, 03:46 PM
  5. percentage in a query
    By Peljo in forum Access
    Replies: 2
    Last Post: 02-27-2008, 10:51 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