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

CALCULATE AVG ON THE COMPUTED FIELD

Status
Not open for further replies.

old123

MIS
Joined
Jun 1, 2005
Messages
31
Location
US
I have a computed field "differnce" which is derived from this formula
Grouped by XX
{FM_300L2.FMPMR}- PREVIOUS({FM_300L2.FMPMR})

I need to find average of the filed "differnce"

It seems easy however when i try to insert summary or create a formula it gave me an error . Please help.
 
To get an average you need at least 2 values, your formula will only return one. What is it you are trying to accomplish? Also your version of crystal and the exact text ofthe error message would be helpful.

Software Sales, Training, Implementation and Support for Macola, eSynergy, and Crystal Reports
 
Iam using Crystal Ver 9

Below is the output & last field is the differnce field
The differnce field is the basically a mileage . I need to find the average of breakdown mileage for the group PB0001
In this case output will be somewhere close to 5800

formula : Average ({@DIFFERNCE})
Error : This field cannot be summarized.

PB0001 79243
PB0001 84739 5,496.00
PB0001 90445 5,706.00
PB0001 96393 5,948.00
PB0001 101853 5,460.00
PB0001 107828 5,975.00
PB0001 113590 5,762.00
PB0001 119600 6,010.00
PB0001 125031 5,431.00
PB0001 131078 6,047.00
PB0001 137012 5,934.00
PB0001 142839 5,827.00
PB0001 148605 5,766.00
PB0001 154616 6,011.00
PB0001 160236 5,620.00
PB0001 165870 5,634.00
PB0001 171609 5,739.00
 
Try creating three formulas:

//{@reset} to be placed in the group header:
whileprintingrecords;
numbervar summiles;
numbervar counter;
if not inrepeatedgroupheader then
(summiles := 0;
counter := 0;)

//{@accum} to be placed in the detail section:
whileprintingrecords;
numbervar summiles;
numbervar counter;

if {table.groupfield} = previous({table.groupfield}) then
(
summiles := summiles + {@difference};
counter := counter + 1;
)

//{@ave} to be placed in the group footer:
whileprintingrecords;
numbervar summiles;
numbervar counter;

if counter > 0 then
summiles/counter else 0

-LB
 
Thanks it worked fine however I don't want to display the formula "counter" in the detail .
 
It is fine to suppress the formula. Right click on it->format field->common->suppress.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top