Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Average of a summary field Post Reply Post New Topic
Author Message
jjthed
Newbie
Newbie


Joined: 15 Aug 2014
Online Status: Offline
Posts: 20
Quote jjthed Replybullet Topic: Average of a summary field
    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!

IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet 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})
|< /\ '][' ( )
IP IP Logged
jjthed
Newbie
Newbie


Joined: 15 Aug 2014
Online Status: Offline
Posts: 20
Quote jjthed Replybullet 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?
IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet 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})
|< /\ '][' ( )
IP IP Logged
jjthed
Newbie
Newbie


Joined: 15 Aug 2014
Online Status: Offline
Posts: 20
Quote jjthed Replybullet 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!!
IP IP Logged
jjthed
Newbie
Newbie


Joined: 15 Aug 2014
Online Status: Offline
Posts: 20
Quote jjthed Replybullet 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...
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.