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

Maximum of a Count 2

Status
Not open for further replies.

groasa

Technical User
Jun 14, 2001
39
0
0
US
Using CR8.5

I have a ID field that I am summarizing using Count grouped by Date Recorded (every month). I want to be able to find the numbers for the Maximum and the Minimum Count by month and eventually use them for a subreport.

I'm pretty sure I can't do a formula or a running total to get the max/min count, but does anyone know of a different way I can get this number? Finagling formulas are OK with me :)

Month Table.ID
----- --------
Jan 1 123.111
Jan 2 123.112
------------------
Jan Total 2 = Count of Table.ID

Feb 1 123.113
Feb 1 123.114
Feb 3 123.115
Feb 6 123.116
-----------------
Feb Total 4

Mar 1 123.117
Mar 1 123.118
Mar 3 123.119
-----------------
Mar Total 3

Max = 4 (Feb)
Min = 2 (Jan)
 
Use a formula in the Group Footer to maintain in two global (or shared) variables the lowest and highest values encountered.

You can then use these values, but only in the report footer...

Cheers,
- Ido

CUT, Visual CUT, and DataLink Viewer:
view, e-mail, export, burst, distribute, and schedule Crystal Reports.
 
What type of formula would I use? I keep trying to use a Maximum formula, but since I can't do it on a count, it tells me that the summary/running total could not be created.

What am I missing here? Could you give me an example of the formula?

Thanks,
Glenda
 
The formula simply compares the count (in each group footer) to the value stored in the variable. It replaces the value in the variable with the value of the count in the count is greater than (or less than for the min) the value in the variable.

Cheers,
- Ido

CUT, Visual CUT, and DataLink Viewer:
view, e-mail, export, burst, distribute, and schedule Crystal Reports.
 
You would place a formula {@maxmin} like the following in your group footer:

whileprintingrecords;
numbervar max;
numbervar min;

if count({table.tableID}, {table.date}, "monthly") > max then
max := count({table.tableID}, {table.date}, "monthly") else
max := max;

if groupnumber = 1 then min := count({table.tableID}, {table.date},"monthly") else
if count({table.tableID}, {table.date},"monthly") >= min then
min := min else
min := count({table.tableID}, {table.date},"monthly");

Then in the report footer, you would add two formulas:

{@displaymin}:
whileprintingrecords;
numbervar min;

{@displaymax}:
{@displaymin}:
whileprintingrecords;
numbervar max;

if you want to share these numbers with a subreport placed in a lower report footer section, add "shared" in front of every reference to "numbervar" in the above formulas. You would then have to reference the shared numbervar min and max in your subreport.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top