Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Running Variable? Post Reply Post New Topic
Author Message
dwessell
Newbie
Newbie


Joined: 11 Dec 2007
Online Status: Offline
Posts: 8
Quote dwessell Replybullet Topic: Running Variable?
     Posted: 03 Nov 2009 at 1:55pm
Hi all, I'm using CR 2k8... My report outline looks something like:

Report Header
Page header a
Page header b
Group Header #1a
Group Header #1b
Details
Group Footer #1a
Group Footer #1b
Report Footer
Page Footer
----

In the details section I have two formula fields. One is an sum of two items in that same detail (Plus/Minus_, and the second is a running average of the Plus/Minus.

How can I setup a third item, that would start at 100 when the report is run, and increment based on the average field?

For example, if the average field is > 1 the third item would increase by 1, to 101..

Thanks
David
IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Posted: 04 Nov 2009 at 5:31am
Are you looking to reset to 100 based on whether the group changes?
If not, put the folowing formula field in the Report header, if so, put it in the Group Header:
 
global numbervar nIncrement:=100;
 
Place this next formula field in the details section (I believe this is where you want it):
 
global numbervar nIncrement:=nIncrement + (if {table.average}>1 then 1 else 0);
nIncrement;
 
This should get you what you're looking for.
 
IP IP Logged
dwessell
Newbie
Newbie


Joined: 11 Dec 2007
Online Status: Offline
Posts: 8
Quote dwessell Replybullet Posted: 04 Nov 2009 at 7:46am
@FrnhGLI.. Thank you for that.. I have amended your forumla slightly.. But apperantly have gotten the syntax of CR incorrectly.. Can you point at what I'm goofing?

global numbervar nIncrement:=nIncrement +
(if {#RTotal0}<(-20) then -2 else 0);
(if {#RTotal0}<(-15) and {#RTotal0} > (-20) then -1.5 else 0);
(if {#RTotal0}<(-10) and {#RTotal0} > (-15) then -1 else 0);
(if {#RTotal0}<(-05) and {#RTotal0} > (-10) then -.5 else 0);
nIncrement;

-----

Thanks
David
IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Posted: 04 Nov 2009 at 7:59am
Try this:
 
global numbervar nIncrement:=nIncrement -
(if {#RTotal0}<=(-20) then 2 else
if {#RTotal0}<=(-15) and {#RTotal0} > (-20) then 1.5 else
if {#RTotal0}<=(-10) and {#RTotal0} > (-15) then 1 else
if {#RTotal0}<=(-05) and {#RTotal0} > (-10) then .5 else 0);
nIncrement;
 
I'm not sure if you need the parenthasis around the negative numbers, though, so if you get another error, try removing those.
 
Also, I only put the equal signs in because your formula was leaving out what to do if {#RTotal0} is equal to those numbers. You may need to play around with this to suit your needs.
IP IP Logged
dwessell
Newbie
Newbie


Joined: 11 Dec 2007
Online Status: Offline
Posts: 8
Quote dwessell Replybullet Posted: 04 Nov 2009 at 8:27am
Got it:

global numbervar nIncrement:=nIncrement +
if {#RTotal0}>(20) then -2
else if {#RTotal0}>(15) and {#RTotal0} < (20) then -1.5
else if {#RTotal0}>(10) and {#RTotal0} < (15) then -1
else if {#RTotal0}>(05) and {#RTotal0} < (10) then -.5 else 0;
nIncrement;

My last remaining question.. How can I have this formula work on the last value of #RTotal0 only?

That is it averages items in the detail. But it repeats for each record in the group. Where that formula is concerned, I'm only interested in the final value. The result..

Thanks
David
IP IP Logged
dwessell
Newbie
Newbie


Joined: 11 Dec 2007
Online Status: Offline
Posts: 8
Quote dwessell Replybullet Posted: 04 Nov 2009 at 8:28am
@FrnhtGLI.. I didn't see your post above regarding the changed formula.. Thanks!!
IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Posted: 04 Nov 2009 at 9:53am
Do you still want it to display in the detail section or in the group footer?
 
For Group Footer:
 
1. Suppress the main formula field in the detail section.
2. Create a new formula field and place it in the Group Footer:
 
global numbervar nIncrement
 
For Detail Section:
 
1. Right-click main formula field in the detail section ->Format Field ->Common Tab-> Suppress Formula button.
2. Type not onlastrecord
 
That should do it. Let me know if that works for you.
IP IP Logged
dwessell
Newbie
Newbie


Joined: 11 Dec 2007
Online Status: Offline
Posts: 8
Quote dwessell Replybullet Posted: 04 Nov 2009 at 11:24am
@FrnhtGLI

Thanks for all of your time. I've learned alot from this.
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