Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Help with forumula to average most recent 3 record Post Reply Post New Topic
Author Message
flanman
Senior Member
Senior Member
Avatar

Joined: 04 Nov 2009
Online Status: Offline
Posts: 123
Quote flanman Replybullet Topic: Help with forumula to average most recent 3 record
     Posted: 10 Dec 2009 at 10:51am
I have a project where I have to come up with an average of a field over the last 3 most recent events.

Events Field  = Drive ID (I want the 3 most recent. This is a numeric field)
Procedure Field = Field I want to sum last three an then average

The formula should something like this, but I am not having any luck.

(sum (Procedure Field(3,EventsField)) / 3

Any help is greatly appreciated.

Flanman
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 11 Dec 2009 at 7:31am
if you have a group you can probably to a top N on it. I haven't used but DBlank has.
 
The sum function probably doesn't understand what you are asking for, as that is not the correct syntax.  Sum will sum  a field over a group, and only wanting the top 3.
 
I would probably use shared variables to determine the sum part, if I wanted to see more data than just the last 3 entries. If I only want to see the last 3, or only the average of the last 3, I would look into the the Top N type of report.
 
HTH
IP IP Logged
flanman
Senior Member
Senior Member
Avatar

Joined: 04 Nov 2009
Online Status: Offline
Posts: 123
Quote flanman Replybullet Posted: 11 Dec 2009 at 8:01am
Ok so forgive my ignorace, but  so far I have the report grouped by date. This gives me a single entry for each record. The field(s) I want to get an average from are from previous dates. Not sure how I would set up that grouping.
Here is a little sample of what I want

AccountName (grouped)
EventDate,SalesPerson,#signed up, (Avg signups for last 3 events)

What I am trying to do is compare my current number of sign up for an event to average of the last  three events for the same AccountName.

Flanman
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 11 Dec 2009 at 8:21am
Sorry, I do not think Top N won't work on this problem. It works nicely with numbers but not so much with dates. I will mess around with the concept but I recommend going a different route.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 11 Dec 2009 at 9:27am
OK, what I would do, is have a group based on date, or sorted on date in the order that you want.
 
Then I would have a formula with some shared variables, something like:
shared numbervar iCount;
shared numbervar iSum;
 
if iCount < 3 then (
  iSum := iSum + {table.field};
  iCount := iCount + 1;
)
 
""//hide the formula
 
in the group header you will need a reset, like:
shared numbervar iCount:=0;
shared numbervar iSum := 0;
""
 
where you want the average, the formula would be like:
shared numbervar iSum;
iSum/3
 
HTH
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