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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tough Count situation 1

Status
Not open for further replies.

Sose

Technical User
Jan 4, 2002
7
US
I have a field named "Charge" that will either have a value of 0 or 1, for a number of records.

I need to count every instance (over a period of a month) of 0 and 1, until they equal 360, and then only count every instance of 1 after that for the rest of the month.

Is this possible?
 
hi,

You should be able to do it using three formulae. Eg...
---------------
{@gh_reset} // add to group header, suppress field
numbervar tot := 0;
tot
---------------
@rec_tot} // add to record, suppress field
numbervar tot:=0;
if tot < 360 then
(if {field} in [0,1] then tot := tot + 1)
else
if {field} = 1 then tot := tot + 1;
tot
---------------
{@gf_out} // add to group footer
numbervar tot;
tot
---------------


Hth,
Geoff
 
The only thing that I would add is that, if you have inaccuracies when testing your report (perhaps if you have some sorting enabled on your report), you may need to add

[tt]
WhilePrintingRecords;
[/tt]

at the top of each one of Geoff's formulas. If you're into programming and have CR 8.x, you could also use a &quot;Do ... While&quot; loop with only one formula.

Regards, John Marrett
Crystal Reports & Crystal Enterprise Trainer
 
How do I get the array to know which field to pull information from?

I keep getting &quot;This field name is not known&quot;

Thanks so much for your help.
 
I went ahead and joined up here.. And, I realized I may have confused an array with a boolean formula.. Regardless, I think the issue is the same..
 
Sounds as if you haven't worked with variables before... Let's say that the field you want to count is called Table.Charge. Taking Geoff's example above, there would be no changes in the formulas [tt]{@gh_reset}[/tt] & [tt]{@gf_out}[/tt]. [tt]@rec_tot[/tt] would look like this:

[tt]
@rec_tot} // add to record, suppress field
numbervar tot:=0;
if tot < 360 then
(if {Table.Charge} in [0,1] then tot := tot + 1)
else
if {Table.Charge} = 1 then tot := tot + 1;
tot
[/tt]

Try that and see if it works for you. If it doesn't tell us what you're using as a formula as well as the table & field name.

Regards,
John Marrett
Crystal Reports & Crystal Enterprise Trainer
 
If I take out:

@rec_tot}

This is what I have:

WhilePrintingRecords;

numbervar tot:=0;
if tot < 360 then
(if {TASKS.CHARGE} in [0,1] then tot := tot + 1)
else
if {TASKS.CHARGE} = 1 then tot := tot + 1;
tot

And the output is 1.00
 
Sorry but there is a bug in this formula:

************************

@rec_tot} // add to record, suppress field
numbervar tot:=0;
if tot < 360 then
(if {Table.Charge} in [0,1] then tot := tot + 1)
else
if {Table.Charge} = 1 then tot := tot + 1;
tot

*****************************

the value of &quot;tot&quot; is constantly being reset to ZERO

tot is set to zero using the intialization formula which is put in the report header (or elsewhere depending on if you want to reset the value of tot for another group total)

numberVar tot := 0

should be

numberVar tot;
 
This is what I have, exactly:

@rec_tot} // add to record, suppress field
numberVar tot := 0
if tot < 360 then
(if {Table.Charge} in [0,1] then tot := tot + 1)
else
if {Table.Charge} = 1 then tot := tot + 1;
tot

And I still get the &quot;The reamining text...&quot; error, right where:
@rec_tot}
is.
 
Hi,

The function rec_tot needs to be changed to ...

numbervar tot;
if tot < 360 then
(if {Table.Charge} in [0,1] then tot := tot + 1)
else
if {Table.Charge} = 1 then tot := tot + 1;
tot


Hth,
Geoff


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top