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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with Previous() function and running totals

Status
Not open for further replies.

Storyteller

Instructor
Apr 19, 1999
343
CA
Hello All,
I am using the 3 formula routine to calculate a running total with variables.
The formulas are: (note I really only needed 2)

@ACB/Share Initialize
WhilePrintingRecords;
CurrencyVar ACBperShareRunningTotal;
ACBperShareRunningTotal:={Avg_Cost_at_010101.Average Cost};

@ACB/Share Evaluate
EvaluateAfter ({@ACB Evaluate});
CurrencyVar ACBperShareRunningTotal;
ACBperShareRunningTotal:= If {@S Evaluate}=0
Then ACBperShareRunningTotal:=0
Else ACBperShareRunningTotal:=({@ACB Evaluate}/{@S Evaluate});// A running total/running total
//@ACB Evaluate and @S Evaluate are on the same line as @ACB/Share Evaluate, so I need them to be evaluated first.


My problem is that when I try to do the following:
Previous(@ACB/Share Evaluate) I get the following message "This Field has No Previous or Next Value". The frustrating part of this is that I can see the value when I run the report.

I've experimented with a number of {Fields} and {@Formulas} and the Previous() function works. It is just when I try to use it with any of the Running total formulas {@ACB Evaluate}, {@ACB/Share Evaluate}, {@S Evaluate} is when I get the error message.

Needless to say I'm getting frustrated. Any help would be greatly appreciated.

Thanks,
Michael
 
try adding "WhilePrintingRecords" to {@ACB/Share Evaluate}

Your initialize formula has it so you should be consistant and do this evaluation at the same printstate
 
You can't use Previous with a field that is built "WhilePrintingRecords", like a running total.

But I don't see any running totals, or any need of variables in these 2 formulas. This is simply an If-Then-Else statement. You could simply use:

//@ACB/Share Evaluate

If {@S Evaluate} = 0
then 0
Else {@ACB Evaluate}/{@SEvaluate}

Then, unless the formulas mentioned here have variables or sumamries in them, you can use previous and next. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Hello All,

To clarify
Number of Shares is a running total calculation: [@S Evaluate}
Adjusted Cost Base is a running total calculation: {@ACB Evaluate}
ACB/Share {@AvgCostRunning} is: {@ACB Evaluate}/{@S Evaluate}
So what I have is a running total divided by a running total.

What I need to do is calculate the Cost Disposals. Which is a calculation of the ChangeInUnits * the Previous ACB/Share. I have created the following formula:

{@C Disposals}
If {InvestTrans.TransType} = "Sell"
Then {InvestTrans.ChangeInUnits}*{@AvgCostRunning}
// I would prefer to use . . .
// Then {InvestTrans.ChangeInUnits}*previous({@AvgCostRunning})
// the error message I get is "This field has no previous or next value"

I have tried to assign the {@AvgCostRunning} to another variable then used the Previous() function, but I still got the same error. I tried using multiple "Details" sections then "Underlay following with no success.

The only thing I haven't done is to create a sub-report, but I don't think it will work, since the calculation will still be based off of a formula with an Evaluation Time Function.

I have received tremendous help and support from Tek-Tips members, but I think the truth is that you cannot use Previous() function with a calculation that includes Evaluation Time Functions.

If anyone has anyother leads for me to follow I would be greatly appreciative. When I figure this out I will definitely be posting the solution.

Michael
 
The only way to get the previous value of a variable is to store it in a variable while on the previous record. You then have to use it on the current record BEFORE you store the current value to use in the next record.

You might be able to do this in one formula, but you should certainly be able to do it in Two. To make it clearer you can split the section into A and B and put the formula that assigns in B and the formula that uses in A so that it alwasy occurs first. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top