Tips and Tricks
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Tips and Tricks
Message Icon Topic: Difference between two records Post Reply Post New Topic
Author Message
pebe
Newbie
Newbie
Avatar

Joined: 19 Mar 2009
Location: Belgium
Online Status: Offline
Posts: 2
Quote pebe Replybullet Topic: Difference between two records
    Posted: 19 Mar 2009 at 3:16am
Hi,
 
Probably a stupid question but I cannot find a solution...
 
I'm trying to calculate the differen between a record and the previous record but can't figure out how to.
 
Eg,
ID, Value
1, 500
2, 600
3, 550
 
I would like to get the difference between 2 and 1, 3 and 2
Results should be like
2, 100
3, -50
 
Thnx,
Peter 
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 19 Mar 2009 at 7:22am
{Table.ValueField} - previous({Table.ValueField})
 
Make sure your record sort is on the ID field
IP IP Logged
pebe
Newbie
Newbie
Avatar

Joined: 19 Mar 2009
Location: Belgium
Online Status: Offline
Posts: 2
Quote pebe Replybullet Posted: 19 Mar 2009 at 7:44am
So simpel Embarrassed
 
Thnx for the help.
 
Kind regards,
Peter
IP IP Logged
AdamField
Groupie
Groupie


Joined: 04 Jun 2009
Online Status: Offline
Posts: 88
Quote AdamField Replybullet Posted: 04 Jun 2009 at 6:24am
Hi,
 
in addition to this question is it possible to do a count like this over a given fixed value ?
 
like
 
Data1    10550
Data1    450
Data1    300
Data1    200
Data2    900
Data2    300
Data2    100
 
so do that count of the first record - the second - the 3e until the date changes
 
so for example if grouped on date it gives for data1  9600
and for Data2 500
 
Tnx already !!
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 04 Jun 2009 at 7:25am

I think the most efficient way to do this would be to use a variable which is not my comfort zone so let me  pass this off to someone that is better at that...

IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 04 Jun 2009 at 7:38am

Hi,

DBlank asked for me to help you out with shared variables as this is a method to accomplish what you are looking at.
 
Shared variables usually involve 3 formulas, 1) to initialize the variable (usually 0, but not in this case), 2) increment the variable, and 3) display the results.  In your case they would look something like:
 
in the group header, initialize:
shared numbervar counter := 0;  //on second thought, this might be better
""  //to hide the formua's output, you could supress the formula (I think)
 
in the detail section:
shared numbervar counter;
if counter = 0 then
  counter := {table.field}
else
 counter := counter - {table.field};
""  //again to hide the output (remove this line for debugging)
 
in the group footer:
shared numbervar counter
 
 
this can also be used for the differencing if desired with but a few modifications, but if something is working, why mess with it ;)
 
HTH
IP IP Logged
AdamField
Groupie
Groupie


Joined: 04 Jun 2009
Online Status: Offline
Posts: 88
Quote AdamField Replybullet Posted: 04 Jun 2009 at 7:50am
tnx a lot for this !!
 
i'll go for it first thing 2 morrow morning
 
ps: i like to mess with stuff that's the reason i'm doing the report here internal :p
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.023 seconds.