Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Average Group Post Reply Post New Topic
Author Message
danboy
Newbie
Newbie
Avatar

Joined: 26 Nov 2012
Location: United Kingdom
Online Status: Offline
Posts: 12
Quote danboy Replybullet Topic: Average Group
    Posted: 26 Nov 2012 at 5:46am
Hello,
 
I'm trying to do an average for the number of calls for each day. I have created the group which calculates the total number of tickets by day as shown below:
 
Do I need a variable, thought this would be easy enough for seems tricky...
 
Thanks
 
DateRecieved  CountOfTickets
 
01/11/2012 24
02/11/2012 30
05/11/2012 25
06/11/2012 36
07/11/2012 41
08/11/2012 40
09/11/2012 25
12/11/2012 36
13/11/2012 29
14/11/2012 345
15/11/2012 195
16/11/2012 29
18/11/2012 1
19/11/2012 50
20/11/2012 38
21/11/2012 47
22/11/2012 31
23/11/2012 32
25/11/2012 1
Total 1,053
Average ???
 
IP IP Logged
Sastry
Moderator
Moderator
Avatar

Joined: 16 Jul 2012
Online Status: Offline
Posts: 537
Quote Sastry Replybullet Posted: 26 Nov 2012 at 6:54pm
HI
 
You need to count the groups to get average.
 
Try this formula :
 
Whileprintingrecords;
numbervar x;
x:=x+1  // place this on your group
 
and create one more formula to get average :
 
Whileprintingrecords;  // Place this formula where you want to show average.
numbervar x;
{YourTotalTickets) / x;
 
Thanks,
Sastry
IP IP Logged
danboy
Newbie
Newbie
Avatar

Joined: 26 Nov 2012
Location: United Kingdom
Online Status: Offline
Posts: 12
Quote danboy Replybullet Posted: 26 Nov 2012 at 8:57pm
Hi,
 
This worked but now I get a Division by zero error on this field even though it worked first time, can this be cleaned up as the formula is correct?
 
I tried this:
 
Whileprintingrecords;  // Place this formula where you want to show average.
numbervar x;
if {@CountTickets} / x = 0 then 0 else
{@CountTickets} / x;
 
same error
 
and this:
 
Whileprintingrecords;  // Place this formula where you want to show average.
numbervar x;
if {@GrpAvgForm} / x = 0 then //group formula
{@CountTickets} / x;
 
Calculates all tickets 
 
Thanks


Edited by danboy - 26 Nov 2012 at 10:08pm
IP IP Logged
danboy
Newbie
Newbie
Avatar

Joined: 26 Nov 2012
Location: United Kingdom
Online Status: Offline
Posts: 12
Quote danboy Replybullet Posted: 26 Nov 2012 at 10:27pm
Just tried this:
 
Whileprintingrecords;  // Place this formula where you want to show average.
numbervar x;
if {@GrpAvgForm} / x = 0 then 0 else
{@CountTickets} / x;
 
When I out the formula in the header it counts all tickets, when I put it in the report footer it calculates a figure of 52 but checking the average in Excel the figure is 55?
IP IP Logged
danboy
Newbie
Newbie
Avatar

Joined: 26 Nov 2012
Location: United Kingdom
Online Status: Offline
Posts: 12
Quote danboy Replybullet Posted: 26 Nov 2012 at 10:40pm
The below formula works but only in the report footer, really want to be able to place the formula anywhere? any help you can give to eliminate the division by zero error would be good.
 
Whileprintingrecords;  // Place in report footer only.
numbervar x;
//if {@GrpAvgForm} / x = 0 then 0 else
If x = 0 then 0 else
{@CountTickets} / x;
IP IP Logged
Sastry
Moderator
Moderator
Avatar

Joined: 16 Jul 2012
Online Status: Offline
Posts: 537
Quote Sastry Replybullet Posted: 27 Nov 2012 at 1:16am
Hi
 
I am trying to count number of date grups and that should devide your sum of all date tickets.
 
My first formula will increase the 'x' variable value when it encounter a new group.  So, this formula always on your group header or group footer.
 
2nd formula is going to divide sum of your tickets by count.  If you are getting devide by zero error means, placing of formulas in wrong sections.  Only you should get division by zero when you don't have any data.
 
Try this in my second formula :
 
Whildprintingrecords;
numbervar x;
if x <> 0 then {@CountTickets} / x
else
0
 
 
Thanks,
Sastry
IP IP Logged
danboy
Newbie
Newbie
Avatar

Joined: 26 Nov 2012
Location: United Kingdom
Online Status: Offline
Posts: 12
Quote danboy Replybullet Posted: 27 Nov 2012 at 1:40am
Hi
 
I understand that, the below is in the group header:
 
Whileprintingrecords;
numbervar x;
x:=x+1  // place in group
 
The formula does work in the report footer not the report header where it is returning the division by zero error...
 
the new one also does not work in the report header but does in the report footer...
 
Thanks
IP IP Logged
Sastry
Moderator
Moderator
Avatar

Joined: 16 Jul 2012
Online Status: Offline
Posts: 537
Quote Sastry Replybullet Posted: 27 Nov 2012 at 2:12am
Hi
 
This is a running total and if you place this on report header then the initial value of the variable is always zero. So, it will not work any time.
 
It will work only in report footer.
 
Thanks,
Sastry
IP IP Logged
danboy
Newbie
Newbie
Avatar

Joined: 26 Nov 2012
Location: United Kingdom
Online Status: Offline
Posts: 12
Quote danboy Replybullet Posted: 27 Nov 2012 at 2:20am
Hi
 
Thanks for your help much appreciated, it did honestly work in the report header after a refresh, strange...good to have the solution though so thanks again.
 
:)
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.030 seconds.