Solved

Percent of Total results from a query

Posted on 2003-11-19
15
831 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Suggested Solutions

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now