A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Count IF Query



 
 
Thread Tools Display Modes
  #1  
Old February 16th, 2007, 10:35 AM posted to microsoft.public.access.queries
richardwo
external usenet poster
 
Posts: 16
Default Count IF Query

Hello,

I have a query with two fields, Patient Name and FollowUp. FollowUp is a
"Yes/No" field and I would like to show a list of patients with the number of
followUps they had.

This is what I did:

Field: Name FollowUp
Table: tblClinic
Total: Group By Count
Sort:
Show:
Criteria:

The above query returns a list of patients and the total number of followups
they each had, BUT, includes patients who had "No" in the FollowUp field e.g.
John Smith had 3 visits to a clinic but only 2 followups but the query
returns a value of 3 in the FollowUp field.

Is there anyway of calculating the number of actual followups for each
patient i.e. the number of yes's in the followup field.

Thank you in advance. Rich

  #2  
Old February 16th, 2007, 11:55 AM posted to microsoft.public.access.queries
Jason Lepack
external usenet poster
 
Posts: 600
Default Count IF Query

This will show a list of people and their number of yes' but will not
include the people with 0 yes'

Field: Name FollowUp
Table: tblClinic
Total: Group By Count
Sort:
Show:
Criteria: Yes

Cheers,
Jason Lepack


On Feb 16, 5:35 am, richardwo
wrote:
Hello,

I have a query with two fields, Patient Name and FollowUp. FollowUp is a
"Yes/No" field and I would like to show a list of patients with the number of
followUps they had.

This is what I did:

Field: Name FollowUp
Table: tblClinic
Total: Group By Count
Sort:
Show:
Criteria:

The above query returns a list of patients and the total number of followups
they each had, BUT, includes patients who had "No" in the FollowUp field e.g.
John Smith had 3 visits to a clinic but only 2 followups but the query
returns a value of 3 in the FollowUp field.

Is there anyway of calculating the number of actual followups for each
patient i.e. the number of yes's in the followup field.

Thank you in advance. Rich



  #3  
Old February 16th, 2007, 12:18 PM posted to microsoft.public.access.queries
richardwo
external usenet poster
 
Posts: 16
Default Count IF Query

Appreciate the help Jason, but this doesn't work. I thought of this myself
but when you run the query it returns exactly the same result ad without the
"yes".

"Jason Lepack" wrote:

This will show a list of people and their number of yes' but will not
include the people with 0 yes'

Field: Name FollowUp
Table: tblClinic
Total: Group By Count
Sort:
Show:
Criteria: Yes

Cheers,
Jason Lepack


On Feb 16, 5:35 am, richardwo
wrote:
Hello,

I have a query with two fields, Patient Name and FollowUp. FollowUp is a
"Yes/No" field and I would like to show a list of patients with the number of
followUps they had.

This is what I did:

Field: Name FollowUp
Table: tblClinic
Total: Group By Count
Sort:
Show:
Criteria:

The above query returns a list of patients and the total number of followups
they each had, BUT, includes patients who had "No" in the FollowUp field e.g.
John Smith had 3 visits to a clinic but only 2 followups but the query
returns a value of 3 in the FollowUp field.

Is there anyway of calculating the number of actual followups for each
patient i.e. the number of yes's in the followup field.

Thank you in advance. Rich




  #4  
Old February 16th, 2007, 12:33 PM posted to microsoft.public.access.queries
stumac
external usenet poster
 
Posts: 165
Default Count IF Query

try:

Field: nooffollowups: IIF(FollowUp = Yes,1,0)
Table: tblClinic
Total: Group By Count
Sort:
Show:
Criteria:

Hth

Stu


"richardwo" wrote:

Appreciate the help Jason, but this doesn't work. I thought of this myself
but when you run the query it returns exactly the same result ad without the
"yes".

"Jason Lepack" wrote:

This will show a list of people and their number of yes' but will not
include the people with 0 yes'

Field: Name FollowUp
Table: tblClinic
Total: Group By Count
Sort:
Show:
Criteria: Yes

Cheers,
Jason Lepack


On Feb 16, 5:35 am, richardwo
wrote:
Hello,

I have a query with two fields, Patient Name and FollowUp. FollowUp is a
"Yes/No" field and I would like to show a list of patients with the number of
followUps they had.

This is what I did:

Field: Name FollowUp
Table: tblClinic
Total: Group By Count
Sort:
Show:
Criteria:

The above query returns a list of patients and the total number of followups
they each had, BUT, includes patients who had "No" in the FollowUp field e.g.
John Smith had 3 visits to a clinic but only 2 followups but the query
returns a value of 3 in the FollowUp field.

Is there anyway of calculating the number of actual followups for each
patient i.e. the number of yes's in the followup field.

Thank you in advance. Rich




  #5  
Old February 16th, 2007, 12:38 PM posted to microsoft.public.access.queries
stumac
external usenet poster
 
Posts: 165
Default Count IF Query

Oops, change count to sum. Count will count all records regardless of its
value!

"stumac" wrote:

try:

Field: nooffollowups: IIF(FollowUp = Yes,1,0)
Table: tblClinic
Total: Group By Count
Sort:
Show:
Criteria:

Hth

Stu


"richardwo" wrote:

Appreciate the help Jason, but this doesn't work. I thought of this myself
but when you run the query it returns exactly the same result ad without the
"yes".

"Jason Lepack" wrote:

This will show a list of people and their number of yes' but will not
include the people with 0 yes'

Field: Name FollowUp
Table: tblClinic
Total: Group By Count
Sort:
Show:
Criteria: Yes

Cheers,
Jason Lepack


On Feb 16, 5:35 am, richardwo
wrote:
Hello,

I have a query with two fields, Patient Name and FollowUp. FollowUp is a
"Yes/No" field and I would like to show a list of patients with the number of
followUps they had.

This is what I did:

Field: Name FollowUp
Table: tblClinic
Total: Group By Count
Sort:
Show:
Criteria:

The above query returns a list of patients and the total number of followups
they each had, BUT, includes patients who had "No" in the FollowUp field e.g.
John Smith had 3 visits to a clinic but only 2 followups but the query
returns a value of 3 in the FollowUp field.

Is there anyway of calculating the number of actual followups for each
patient i.e. the number of yes's in the followup field.

Thank you in advance. Rich



  #6  
Old February 16th, 2007, 12:44 PM posted to microsoft.public.access.queries
Gary Walter
external usenet poster
 
Posts: 613
Default Count IF Query

Look at SQL View to see what you did.
You filtered on Count being "True"
which will evaluate to True for all positive,
non-zero counts.

SELECT
tblClinic.PatientName,
Count(tblClinic.FollowUp) AS CountOfFollowUp
FROM tblClinic
GROUP BY tblClinic.PatientName
HAVING (((Count(tblClinic.FollowUp))=Yes));

One trick is to sum a boolean field (add all the -1's),
then change sign with Abs function. You can also
use this trick for any boolean expression.

SELECT
tblClinic.PatientName,
Count(*) As TotalCnt,
Abs(Sum(tblClinic.FollowUp)) AS CntFollowUps,
Abs(Sum(tblClinic.FollowUp=0)) AS CntNoFollowUps
FROM tblClinic
GROUP BY tblClinic.PatientName

"richardwo" wrote:
Appreciate the help Jason, but this doesn't work. I thought of this myself
but when you run the query it returns exactly the same result ad without
the
"yes".

"Jason Lepack" wrote:

This will show a list of people and their number of yes' but will not
include the people with 0 yes'

Field: Name FollowUp
Table: tblClinic
Total: Group By Count
Sort:
Show:
Criteria: Yes

Cheers,
Jason Lepack


On Feb 16, 5:35 am, richardwo
wrote:
Hello,

I have a query with two fields, Patient Name and FollowUp. FollowUp is
a
"Yes/No" field and I would like to show a list of patients with the
number of
followUps they had.

This is what I did:

Field: Name FollowUp
Table: tblClinic
Total: Group By Count
Sort:
Show:
Criteria:

The above query returns a list of patients and the total number of
followups
they each had, BUT, includes patients who had "No" in the FollowUp
field e.g.
John Smith had 3 visits to a clinic but only 2 followups but the query
returns a value of 3 in the FollowUp field.

Is there anyway of calculating the number of actual followups for each
patient i.e. the number of yes's in the followup field.

Thank you in advance. Rich






  #7  
Old February 16th, 2007, 01:01 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default Count IF Query

Field: IIF(Followup=True,1,Null)
Total: Count

Count counts the existence of a value. A yes/no field always has a value.

Another way to do this
Field: Abs(Sum(Followup))
Total: Expression

Since True = -1 and False = 0 the above sums everything and gives you a
negative number. To get rid of the negative, apply the abs function.

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

"richardwo" wrote in message
...
Hello,

I have a query with two fields, Patient Name and FollowUp. FollowUp is a
"Yes/No" field and I would like to show a list of patients with the number
of
followUps they had.

This is what I did:

Field: Name FollowUp
Table: tblClinic
Total: Group By Count
Sort:
Show:
Criteria:

The above query returns a list of patients and the total number of
followups
they each had, BUT, includes patients who had "No" in the FollowUp field
e.g.
John Smith had 3 visits to a clinic but only 2 followups but the query
returns a value of 3 in the FollowUp field.

Is there anyway of calculating the number of actual followups for each
patient i.e. the number of yes's in the followup field.

Thank you in advance. Rich



  #8  
Old February 16th, 2007, 01:56 PM posted to microsoft.public.access.queries
richardwo
external usenet poster
 
Posts: 16
Default Count IF Query

Thank you all for your help. Got is sorted now thanks to your help John.

"John Spencer" wrote:

Field: IIF(Followup=True,1,Null)
Total: Count

Count counts the existence of a value. A yes/no field always has a value.

Another way to do this
Field: Abs(Sum(Followup))
Total: Expression

Since True = -1 and False = 0 the above sums everything and gives you a
negative number. To get rid of the negative, apply the abs function.

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

"richardwo" wrote in message
...
Hello,

I have a query with two fields, Patient Name and FollowUp. FollowUp is a
"Yes/No" field and I would like to show a list of patients with the number
of
followUps they had.

This is what I did:

Field: Name FollowUp
Table: tblClinic
Total: Group By Count
Sort:
Show:
Criteria:

The above query returns a list of patients and the total number of
followups
they each had, BUT, includes patients who had "No" in the FollowUp field
e.g.
John Smith had 3 visits to a clinic but only 2 followups but the query
returns a value of 3 in the FollowUp field.

Is there anyway of calculating the number of actual followups for each
patient i.e. the number of yes's in the followup field.

Thank you in advance. Rich




 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:23 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.