Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Getting the Average of a Summarized field Post Reply Post New Topic
Author Message
jmiller121
Newbie
Newbie


Joined: 12 Apr 2007
Online Status: Offline
Posts: 5
Quote jmiller121 Replybullet Topic: Getting the Average of a Summarized field
     Posted: 13 Mar 2008 at 11:54am
Crystal Reports XI

Goal:  Determine the average amount of time it takes for the FIRST fire truck to arrive on the scene of an emergency.

Problem:  Not able to "summarize" the formula/running total that contains the values that I want to get the Average of.

Setup:  Database contains the Emergency Runs and the fire trucks that responded to that run.  Rows each contain the amount of time elapsed (in seconds) from the Time of Call to the Time On Scene.  I have a group set up for each Emergency Call, and I have a running total for each group that pulls the Minimum time.  Something like this:

Call #001 (Group Header)
Engine1 - 3:45
Engine2 - 2:34
Engine3 - 6:43
Engine4 - 7:33
RunningTotal for Call#001 - 2:34 (Minimum of above group)

Call #002 (Group Header)
Engine1 - 5:03
Engine2 - 4:33
Engine3 - 1:06
Engine4 - 8:04
RunningTotal for Call#002 - 1:06 (Minimum of above group)

Call #003 (Group Header)
Engine1 - 8:44
Engine2 - 9:33
Engine3 - 6:49
Engine4 - 4:24
RunningTotal for Call#003 - 4:24 (Minimum of above group)


What I need to do is determine the Average of the Running Totals (in this case, the average of 2:34, 1:06, & 4:24)  NOTE:  the times are actually stored as a number (seconds), not as a DateTime field. 

Any advice would be appreciated.  I have read the stuff in the CR Help file on "manual running total", but I still can't seem to get the Average....

Thanks!
Jason Miller




Edited by jmiller121 - 13 Mar 2008 at 12:45pm
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 14 Mar 2008 at 2:05pm
You could try something like this:
First Formula - we'll call this "GetMinTime"
NumberVar MinTime;
if (previousIsNull({call_number})) or
    ({table.call_number} <> previous({call_number}) or
    (MinTime > {seconds to respond}) then
  MinTime := {seconds to respond}
else
  MinTime := MinTime;
MinTime
 
Second Formula - we'll call this "MinTimesTotal"
EvaluateAfter {@GetMinTime};
NumberVar TimeTotal;
if previousIsNull({call number}) then TimeTotal := 0;
TimeTotal := TimeTotal + {@GetMinTime};
TimeTotal
 
Your average then becomes something like this:
if DistinctCount({call_number}) = 0 then  //avoid division by zero
  0
else
  {@MinTimesTotal}/DistinctCount({call_number})
I haven't tested any of this, but hopefully it will point you in the right direction.
 
-Dell
IP IP Logged
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