# Percent of Total results from a query

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.

LVL 1
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
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
Author Commented:
'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
Author Commented:
'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
Author Commented:
'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
Author Commented:
'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
Author Commented:
Sigh... sorry about that, work network said page cannot be displayed
0
Commented:

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
Author Commented:
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
Commented:
Hey sph3rion,

What version of Access are you using?
0
Author Commented:
Access 2000 sir
0
Commented:
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

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
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
Author Commented:
BINGO

I don't have FormatPercent though... is that Access XP?
0
Author Commented:
Thank you so very much by the way :)
0
Commented:
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
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.