Results 1 to 8 of 8
  1. #1
    franciscov is offline Novice
    Windows 10 Access 2021
    Join Date
    Apr 2023
    Posts
    4

    Get percentage over total


    Hi friends, I'm debutting on this forum to solve one question,

    I have an Access table with many orders, each one with his price

    In a query, I'd like to get the percentage of each price respect the amount of prices of all the records.
    I'm using this expression.


    Expr1: ([Price]*100) / Sum([Orders]![Price])


    And I get the error

    Your query does not include the specified expression "Expr1: ([Price]*100) / Sum([Orders]![Price])" as part of an aggregate function.

    Any one does know If I can do this in access (In the same query, work with table amounts), and how to do it?

    This is the SQL code
    SELECT Sum(([Orders]*100)/Sum([Orders]![Price])) AS Expr1
    FROM Table;

    Thanks in advance
    Last edited by franciscov; 04-25-2023 at 02:54 AM. Reason: error

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Use sigma icon on ribbon ( Σ ) to change query design to a Totals query. You could research ms access totals query if you need guidance.
    Note - too many fields in a totals query might cause too many groups.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    franciscov is offline Novice
    Windows 10 Access 2021
    Join Date
    Apr 2023
    Posts
    4
    Quote Originally Posted by Micron View Post
    Use sigma icon on ribbon ( Σ ) to change query design to a Totals query. You could research ms access totals query if you need guidance.
    Note - too many fields in a totals query might cause too many groups.
    The totals query calculates totals over all records, and that's not what I need.

    Anyone knows if there's a way to get it?

  4. #4
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    It only does that if you don't apply criteria.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    you can't combine a sum with a field value in the same query calculation which is why you get your error. Think you need to use a subquery to get the sum. Not clear what you are actually wanting from your sql or description but perhaps something like this air code will show you the way

    Code:
    SELECT Price, Round([price]*100/(select Sum([Price]) from Table AS S),2) AS pCent
    FROM Table;
    for the future, strongly advise provide some example data and the result required from that data - paints a much easier picture to understand rather than a written description

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,943
    Quote Originally Posted by franciscov View Post
    The totals query calculates totals over all records, and that's not what I need.

    Anyone knows if there's a way to get it?
    Hmm, very dismissive response ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    franciscov is offline Novice
    Windows 10 Access 2021
    Join Date
    Apr 2023
    Posts
    4
    Quote Originally Posted by CJ_London View Post
    you can't combine a sum with a field value in the same query calculation which is why you get your error. Think you need to use a subquery to get the sum. Not clear what you are actually wanting from your sql or description but perhaps something like this air code will show you the way

    Code:
    SELECT Price, Round([price]*100/(select Sum([Price]) from Table AS S),2) AS pCent
    FROM Table;
    for the future, strongly advise provide some example data and the result required from that data - paints a much easier picture to understand rather than a written description
    Thank you very much.

  8. #8
    franciscov is offline Novice
    Windows 10 Access 2021
    Join Date
    Apr 2023
    Posts
    4
    Quote Originally Posted by Welshgasman View Post
    Hmm, very dismissive response ?
    Sorry about that, it was not my purpose.

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

Similar Threads

  1. Crosstab Query to show percentage of row total
    By keith2511 in forum Queries
    Replies: 3
    Last Post: 03-20-2019, 12:14 PM
  2. Percentage of Total
    By uaguy3005 in forum Queries
    Replies: 3
    Last Post: 12-22-2015, 01:32 PM
  3. Percentage of Total
    By O.92 in forum Queries
    Replies: 4
    Last Post: 12-03-2015, 01:19 AM
  4. How to get Total Sum to percentage%
    By Kitz14 in forum Queries
    Replies: 1
    Last Post: 07-15-2015, 11:02 PM
  5. Replies: 28
    Last Post: 03-13-2012, 07:48 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