Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: PreviousValue Function Post Reply Post New Topic
Author Message
VictorFresno
Newbie
Newbie


Joined: 08 Dec 2008
Online Status: Offline
Posts: 8
Quote VictorFresno Replybullet Topic: PreviousValue Function
     Posted: 08 Dec 2008 at 4:24pm
How do you reset a PreviousValue formula to for each group change? Because I keep getting a high negative number for my output on the first line of each new group because it's subtracting the Previous Meter Reading from the last group.

My formulas are as follows:

Group Header Section:
whileprintingrecords;
numberVar MilesDiff :=0;

Details Section:
whileprintingrecords;
numbervar MilesDiff;
MilesDiff := {FTK_MAIN.METER_1} - previous({FTK_MAIN.METER_1})

I don't have anything in the Group Footer, though I tried that earlier and still got the same results. Any help is greatly appreciated! Thanks!

IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 09 Dec 2008 at 7:02am
I haven't used previous in my reports, but what I would try is putting a flag in the Group Header Section stating a change, then in the Details Section check the flag, if set, skip the calculation and resest the flag.  The next record through would use the calculation.
 
Also, it seems that you are trying to reset the MilesDiff variable, if so, it should be declared as Shared numberVar in both sections...
 
OR
Group Header Section:
whileprintingrecords;
shared booleanVar newGroup := true;

Details Section:
whileprintingrecords; 
numberVar MilesDiff :=0; 
shared booleanVar newGroup;
 
if not newGroup then   
    MilesDiff := {FTK_MAIN.METER_1} - previous({FTK_MAIN.METER_1})
else
   newGroup := false;
 
MilesDiff
 
Lots of ways.
 
Hope that one of them helps
IP IP Logged
VictorFresno
Newbie
Newbie


Joined: 08 Dec 2008
Online Status: Offline
Posts: 8
Quote VictorFresno Replybullet Posted: 09 Dec 2008 at 8:31am
Thanks for the feedback Lockwelle!

I tried the suggested changes, but received the following error:

"A Number is required here"

for the following line:

else
   newGroup := false;

IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 09 Dec 2008 at 8:41am
Sorry, yeah, crystal wants consistency.
 
Change the booleanVar to a numberVar
Group Header Section:
whileprintingrecords;
shared booleanVar newGroup := true;

Details Section:
whileprintingrecords; 
numberVar MilesDiff :=0; 
shared numberVar newGroup;
 
if newGroup = 0 then   
    MilesDiff := {FTK_MAIN.METER_1} - previous({FTK_MAIN.METER_1})
else
   newGroup := 0;
IP IP Logged
VictorFresno
Newbie
Newbie


Joined: 08 Dec 2008
Online Status: Offline
Posts: 8
Quote VictorFresno Replybullet Posted: 09 Dec 2008 at 9:10am
Got an error because of the discrepancy in Shared Variable Types.

IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 09 Dec 2008 at 9:12am
sorry, follow the consistency and change the booleanVar in the group header to numberVar.
IP IP Logged
VictorFresno
Newbie
Newbie


Joined: 08 Dec 2008
Online Status: Offline
Posts: 8
Quote VictorFresno Replybullet Posted: 09 Dec 2008 at 9:23am
Gotcha! It worked like a charm! Thank you very much! Smile
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