Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count previous three records for each line item

Status
Not open for further replies.

Remedyfix

Programmer
Jan 9, 2004
6
US
Hello,
I have created a formula called @Avg as a line item. My boss would like to have a running total type field next to the @Avg that sums up the @AVG for the previous three records; starting witht he third record in the report.

So my formula starts out like:
If Count(CaseID) > 2


......after that I am lost. Could someone point me in the right direction?

Thanks
 
Your boss is an unusual person.

Please include your version of Crystal and database when posting.

Detail level (hide this section)
whileprintingrecords;
numbervar Sum3;
if recordnumber > 2 then
Sum3 := Sum3+@avg;

Right click the details and select insert section below and place this in a formula in there for display purposes:

whileprintingrecords;
numbervar Sum3;
If recordnumber > 3 and
recordnumber+2/3 = int(recordnumber+2/3) then
Sum3
else
0

Right click the details and select insert section below and place this in a formula in there for resetting (hide this section):

whileprintingrecords;
numbervar Sum3;
If recordnumber > 3 and
recordnumber+2/3 = int(recordnumber+2/3) then
Sum3 := 0;

Should work...

-k
 
That works great. Now (always a NOW).....with that value in the displayed details section, he would like to create another column where the previous value is subtracted from the current value. See example below:

Store Values New column
1
2 1 (where 2-1)
3 1 (where 3-2)

Tried the Previous function but it does not see it. Any suggestions?

thanks.
 
Again, please at least include your version of Crystal when posting.

What you might do is to store the value to another variable so that you can use it later:

So the last formula which resets it would include:

whileprintingrecords;
numbervar Sum3;
numbervar LastSum3;
If recordnumber > 3 and
recordnumber+2/3 = int(recordnumber+2/3) then
LastSum3:= Sum3;
Sum3 := 0;

Now the display line would have an additional formula:
whileprintingrecords;
numbervar LastSum3;
If recordnumber > 3 and
recordnumber+2/3 = int(recordnumber+2/3) then
Sum3-LastSum3
else
0

-k
 
Thank you but I am still getting an error on the formula being displayed:

Now the display line would have an additional formula:
whileprintingrecords;
numbervar LastSum3;
If recordnumber > 3 and
recordnumber+2/3 = int(recordnumber+2/3) then
Sum3-LastSum3
else
0

Also, sorry for not mentioning the other information. We are using Crystal 8.5 on an Access database.

Thanks,
 
Forgot the Sum3 variable declaration:

whileprintingrecords;
numbervar Sum3;
numbervar LastSum3;
If recordnumber > 3 and
recordnumber+2/3 = int(recordnumber+2/3) then
Sum3-LastSum3
else
0

-k
 
I really appreciate your help but it is still not working. Would it be possible to list what each formula should have again from scratch? Maybe I lost something along the way:)

Once again, synapsevampire I really appreciate your help as I am treading new ground here.

Thanks,
 
Is there an email address where I can email this report to you to review?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top