PC Review


Reply
Thread Tools Rate Thread

How do I calculate the percent of "Yes" in a Yes/No Access field?

 
 
=?Utf-8?B?ZnJleWdlMDA=?=
Guest
Posts: n/a
 
      1st Sep 2006
Subjects responded "yes" or "no" and encoded in Access as a Yes/No field.
How can I get Access to calculate the percent of subjects who responded "yes"?
 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      1st Sep 2006
"freyge00" <(E-Mail Removed)> wrote in message
news:2688A910-6798-4F99-AD82-(E-Mail Removed)
> Subjects responded "yes" or "no" and encoded in Access as a Yes/No
> field.
> How can I get Access to calculate the percent of subjects who
> responded "yes"?


In a query:

SELECT
Abs(Sum(YesNoField))/Count(*) AS PercentYes,
Abs(Sum(YesNoField=False))/Count(*) AS PercentNo
FROM YourTable;

You'd need to apply the "Percent" format to the output fields, as
they'll be returned as decimal fractions.

As calculated controls in a form header or footer, or a report
header/footer:

=Abs(Sum(YesNoField))/Count(*)
=Abs(Sum(YesNoField=False))/Count(*)

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
David Cox
Guest
Posts: n/a
 
      2nd Sep 2006
-100 * avg(fieldyn)


"Dirk Goldgar" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "freyge00" <(E-Mail Removed)> wrote in message
> news:2688A910-6798-4F99-AD82-(E-Mail Removed)
>> Subjects responded "yes" or "no" and encoded in Access as a Yes/No
>> field.
>> How can I get Access to calculate the percent of subjects who
>> responded "yes"?

>
> In a query:
>
> SELECT
> Abs(Sum(YesNoField))/Count(*) AS PercentYes,
> Abs(Sum(YesNoField=False))/Count(*) AS PercentNo
> FROM YourTable;
>
> You'd need to apply the "Percent" format to the output fields, as
> they'll be returned as decimal fractions.
>
> As calculated controls in a form header or footer, or a report
> header/footer:
>
> =Abs(Sum(YesNoField))/Count(*)
> =Abs(Sum(YesNoField=False))/Count(*)
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)
>
>



 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      2nd Sep 2006
"David Cox" <(E-Mail Removed)> wrote in message
news:jt4Kg.5344$(E-Mail Removed)
> -100 * avg(fieldyn)


Nice! That's a bit tidier. But I'd rather not rely on the assumption
that Boolean True is always stored as -1, even though that's true in Jet
databases. So I prefer to use the Abs() function, since most databases
I know of store True as either 1 or -1.

100 * Abs(Avg(fieldyn))

The factor 100, of course, converts the decimal fraction to a percent
value. However, it may be desirable to leave it as a fraction and just
format it as a percent, just in case this value is going to be used in
calculations of some sort.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
David Cox
Guest
Posts: n/a
 
      11th Sep 2006
You are, of course, quite correct. I just wanted it to shine without all of
the ifs buts and be carefuls. (Its a weakness)

"Dirk Goldgar" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> "David Cox" <(E-Mail Removed)> wrote in message
> news:jt4Kg.5344$(E-Mail Removed)
>> -100 * avg(fieldyn)

>
> Nice! That's a bit tidier. But I'd rather not rely on the assumption
> that Boolean True is always stored as -1, even though that's true in Jet
> databases. So I prefer to use the Abs() function, since most databases
> I know of store True as either 1 or -1.
>
> 100 * Abs(Avg(fieldyn))
>
> The factor 100, of course, converts the decimal fraction to a percent
> value. However, it may be desirable to leave it as a fraction and just
> format it as a percent, just in case this value is going to be used in
> calculations of some sort.
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)
>
>



 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      11th Sep 2006
"David Cox" <(E-Mail Removed)> wrote in message
news:TGbNg.16710$(E-Mail Removed)
> You are, of course, quite correct. I just wanted it to shine without
> all of the ifs buts and be carefuls. (Its a weakness)


I understand completely. It's hard to write replies that get the job
done in the majority of cases, without burying the reader in lots of
details that are only sometimes relevant. No matter what you write,
someone is going to find something wrong with it. It goes with the
territory.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Field Names: "LongName", "ShortName", "Code", "Description","Comments" PeteCresswell Microsoft Access 2 25th Feb 2009 11:41 PM
How do I calculate "cummulative percent of total" in a pivot table =?Utf-8?B?U3RldmUgUA==?= Microsoft Excel Misc 0 25th Sep 2007 02:06 PM
Trying to filter an Access database with a Field LIKE "%" + "@PARAM" + "%" mosscliffe Microsoft ASP .NET 4 18th May 2006 10:13 PM
"Percent" field changed to "Number" field =?Utf-8?B?VmF1Z2hhbg==?= Microsoft Outlook Form Programming 1 14th Mar 2006 01:32 PM
Calculate "Age" useing a "Birthdate" field (IFF?) =?Utf-8?B?SmVzc2U=?= Microsoft Access 11 11th Jan 2005 11:30 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:15 AM.