Print Page | Close Window

Average of a summary field

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2022
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=21012
Printed Date: 31 Mar 2025 at 12:35am


Topic: Average of a summary field
Posted By: jjthed
Subject: Average of a summary field
Date Posted: 04 Sep 2014 at 12:40pm
Hello,

I am just wondering how do I get the average of a formula?

For example in designer view:   

group 1   unit price
group 2   formula (price/qty)
group 3   (average of group 2)- don't know how to do it??

What it looks like on the report:

       Unit Price

          $7
          $10
          $7
        ______
          $8

Thanks!




Replies:
Posted By: FrnhtGLI
Date Posted: 05 Sep 2014 at 4:17am
You need a sum of the formula for Group 2, divided by the count of the records displayed in Group 2:

sum({@price/qty} , {@group2})/ count ({@price/qty} , {@group2})

-------------
|< /\ '][' ( )


Posted By: jjthed
Date Posted: 05 Sep 2014 at 5:44am
Thanks for the tip, but it gives me an error saying {@price/qty}cannot be summarized. Any suggestions?


Posted By: FrnhtGLI
Date Posted: 05 Sep 2014 at 7:10am
Three Formula Manual Running total to calculate summary.

@INIT_Formula
whileprintingrecords;
global numbervar nPrice/QTY:=0;

@CALC_Formula
whileprintingrecords;
global numbervar nPrice/QTY:=nPrice/QTY + {@price/qty};

@DISP_Formula
whileprintingrecords;
global numbervar nPrice/QTY;

@INIT goes in Group2 Header
@CALC goes on detail line where the summarizing needs to take place
@DISP goes on the line where you want the Average to display.

You can suppress @DISP then create a field that is similar to the previous one:
whileprintingrecords;
global numbervar nPrice/QTY / count ({@price/qty} , {@group2})


-------------
|< /\ '][' ( )


Posted By: jjthed
Date Posted: 05 Sep 2014 at 11:47am
Hrm..... I tried few times, it kept giving me wrong number. I don't use detail section, so the unit price shows in my group 2 section. And this is my first time using a formula doing a manual running total, I am not sure where do I place all the formulas?

Many thanks!!


Posted By: jjthed
Date Posted: 05 Sep 2014 at 11:49am
Just to add, I know you mentioned that one goes to the header, but I don't have any place to put that...



Print Page | Close Window