Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

count on a field when the field value is 2

Status
Not open for further replies.

Mannga

Programmer
Jun 21, 2002
85
0
0
GB
Hi All,
I have just started using Crystal Reports for reporting on my ASP.NET site and have figured out the basics but now I have a problem.

I am trying to create a formula that will give me a count on a field when the field is a 2.

ie. I have the following
Count ({dbt_Patient.pt_Sex},2)
Where {dbt_Patient.pt_Sex} is either equal to 1 or 2.
As far as I can tell this should work.. I have also tried
Count ({dbt_Patient.pt_Sex},{dbt_Patient.pt_Sex},2)

but I am getting the following error message
"The summary / running total field could not be created"

Thanks,
Gavin
 
From your post, it's not clear if you want to count fields equal to 1 or 2, or just 2.

Use a formula saying:
////
whileprintingrecords;
numbervar counter;

if {dbt_Patient.pt_Sex}, in [1,2] then counter := counter + 1 else counter;
////
to bring back 1s and 2s. Otherwise, change "in [1,2]" to "= 2".

Call the variable up with another formula where you want the count displayed. This 2nd formula will just have the first two lines of the 1st formula above.

Naith
 
Apologies: there's an error in my previous post. There should be no comma after the field name.

With regard to your Count formula syntax, try to save the 2nd condition for grouping definition, as opposed to conditional info.

Naith
 
You tried using the "Count (fld, condFld, cond)" format for counting. (quoting from the help file) "cond is a String indicating the type of grouping for condFld. You only specify this argument when condFld is a Date, Time, DateTime or Boolean field. For more information on the valid strings for this argument"

You, however. are looking to count a number. You could use either the running total wizard which will give more options,or a simple formula field to do your counting.

The simple formula is:
numbervar CheckFor2;
if {dbt_Patient.pt_Sex}=2 then CheckFor2:=CheckFor2+1 else CheckFor2:=CheckFor2 Mike

 
Another way that you could do without the variable is to use this formula:

if {dbt_Patient.pt_Sex} = 2 then 1 else 0

then you can do a summary on that.
 
Well thanks to everyone for your replies.....

Your replies have given me what I was looking for... except that I was looking for the wrong thing :)....

What I am trying to do is the following

I have 2 tables,
Table 1 has PatientID and Patient Sex.
Table 2 has PatientID and StartDate

What I need to show is a report that on the left counts up the dates taken from StartDate, then in the next column the amount of males for that day, the next column the amount of females for that day. I also need a total of each which I have now got from the last info you helped me with.

I am sending myself in circles with this thing.

Thanks,
Gavin
 
Create two formula like the one computek353 suggested. One for males and one for females

if {dbt_Patient.pt_Sex} = 2 then 1
and
if {dbt_Patient.pt_Sex} = 1 then 1

Group on the date. Then summarize on the two formulas. Hide your detail section.

Mike

 
You can still use the code I gave you a little while back for this.

Just amend it so that your male variable and your female variable have a counter each:

if X = 'Male' then MaleCounter := MaleCounter+1
else
FemaleCounter := FemaleCounter + 1;

(That assumes that you only have male and female sexes, and does not make allowances for null - or hermaphrodite(!) values.)

I don't know if your join between the two tables is an equal join, and if so, whether there is always a start date. If so, you could just use the RecordNumber special field to count the start dates.

Naith
 
On the 2 tables there is always a StartDate, the only thing is that sometimes the StartDates are the same.

My report should look something like this.

Date Male Female
01 March 2002 1 3
05 March 2002 0 23

So for everyday it adds up the amount of Males and the Amount of Females........ and I just figured it out...

It's weird that when you are trying to explain something you often figure out what you are trying to do.

I now understand what you mean 'mbarron' with the summaries.

This takes a bit of getting used to, it is not as user friendly as I thought it would be.

Thanks for all your help.
Cheers,
Gavin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top