Solved

Percent of Total results from a query

Posted on 2003-11-19
15
834 Views
Last Modified: 2012-06-21
Hello!

Here is my SQL satement thus far for ReasonsQuery:

SELECT DISTINCT SQqryGetOrgWorkedData.Reasons, Count(SQqryGetOrgWorkedData.Reasons) AS CountOfReasons
FROM SQqryGetOrgWorkedData
GROUP BY SQqryGetOrgWorkedData.Reasons
HAVING (((SQqryGetOrgWorkedData.Reasons) Not In ("Closed Correctly")));

This returns a REASON and the total count of that reason within the SQqryGetOrgWorkedData query.

I would like another field, perhaps in this query, but it can be in another query that uses the ReasonsQuery if needed. This field would show the PERCENT for each REASON. So... if the total of all CountOfReasons = 100 and Reason1 = 10, I would like to know that Reason1 is %10 of the total. The "%" sign is not necessary but it would be nice.

Thanks in advance for all your help!
0
Comment
Question by:sph3rion
  • 9
  • 6
15 Comments
 
LVL 5

Expert Comment

by:morpheus30
ID: 9780698
SELECT DISTINCT SQqryGetOrgWorkedData.Reasons, Count(SQqryGetOrgWorkedData.Reasons) AS CountOfReasons, 100 * (SQqryGetOrgWorkedData.Reasons / Count(SQqryGetOrgWorkedData.Reasons)) AS PctOfReasons
FROM SQqryGetOrgWorkedData
GROUP BY SQqryGetOrgWorkedData.Reasons
HAVING (((SQqryGetOrgWorkedData.Reasons) Not In ("Closed Correctly")));
0
 
LVL 1

Author Comment

by:sph3rion
ID: 9780854
'The expression is typed incorrectly, or is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables.'

Is the error I get using that morpheus30.

It went to design view alright though...
0
 
LVL 1

Author Comment

by:sph3rion
ID: 9780855
'The expression is typed incorrectly, or is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables.'

Is the error I get using that morpheus30.

It went to design view alright though...
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 1

Author Comment

by:sph3rion
ID: 9780859
'The expression is typed incorrectly, or is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables.'

Is the error I get using that morpheus30.

It went to design view alright though...
0
 
LVL 1

Author Comment

by:sph3rion
ID: 9780864
'The expression is typed incorrectly, or is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables.'

Is the error I get using that morpheus30.

It went to design view alright though...
0
 
LVL 1

Author Comment

by:sph3rion
ID: 9780872
Sigh... sorry about that, work network said page cannot be displayed
0
 
LVL 5

Expert Comment

by:morpheus30
ID: 9780949
My bad, dude...

I did that carelessly.  Try this...

SELECT DISTINCT SQqryGetOrgWorkedData.Reasons, Count(SQqryGetOrgWorkedData.Reasons) AS CountOfReasons, 100 *(Count(SQqryGetOrgWorkedData.Reasons) / SELECT Count(*) FROM SQqryGetOrgWorkedData)  AS PctOfReasons
FROM SQqryGetOrgWorkedData
GROUP BY SQqryGetOrgWorkedData.Reasons
HAVING (((SQqryGetOrgWorkedData.Reasons) Not In ("Closed Correctly")));
0
 
LVL 1

Author Comment

by:sph3rion
ID: 9781070
Syntax error on: 100 *(Count(SQqryGetOrgWorkedData.Reasons) / SELECT Count(*) FROM SQqryGetOrgWorkedData)

Highlights SELECT

Just as a note, the total count of reasons is not necessarily 100... it's different each time and is probably going to be some odd number like 2567. If that has anything to do with anything, I'm stumped right now.
0
 
LVL 5

Expert Comment

by:morpheus30
ID: 9781116
Hey sph3rion,

What version of Access are you using?
0
 
LVL 1

Author Comment

by:sph3rion
ID: 9781134
Access 2000 sir
0
 
LVL 5

Accepted Solution

by:
morpheus30 earned 500 total points
ID: 9781198
Ooops....

I forgot the Parentheses...

SELECT DISTINCT SQqryGetOrgWorkedData.Reasons, Count(SQqryGetOrgWorkedData.Reasons) AS CountOfReasons, 100 *(Count(SQqryGetOrgWorkedData.Reasons) / (SELECT Count(*) FROM SQqryGetOrgWorkedData))  AS PctOfReasons
FROM SQqryGetOrgWorkedData
GROUP BY SQqryGetOrgWorkedData.Reasons
HAVING (((SQqryGetOrgWorkedData.Reasons) Not In ("Closed Correctly")));
0
 
LVL 5

Expert Comment

by:morpheus30
ID: 9781262
Better yet...

SELECT DISTINCT SQqryGetOrgWorkedData.Reasons, Count(SQqryGetOrgWorkedData.Reasons) AS CountOfReasons, FormatPercent(Count(SQqryGetOrgWorkedData.Reasons) / (SELECT Count(*) FROM SQqryGetOrgWorkedData), 2)  AS PctOfReasons
FROM SQqryGetOrgWorkedData
GROUP BY SQqryGetOrgWorkedData.Reasons
HAVING (((SQqryGetOrgWorkedData.Reasons) Not In ("Closed Correctly")));
0
 
LVL 1

Author Comment

by:sph3rion
ID: 9781353
BINGO

I don't have FormatPercent though... is that Access XP?
0
 
LVL 1

Author Comment

by:sph3rion
ID: 9781361
Thank you so very much by the way :)
0
 
LVL 5

Expert Comment

by:morpheus30
ID: 9781381
hmmm...

The FormatPercent is supposed to be a standard VBScript function.  As a matter of fact, I am using Access XP, but in Access 2000 format.  It is quite possible that they made a change to support this function in XP and not in 2000.  

Anyway, glad things worked out for you!

0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question