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

Calculating the difference between two numbers in a group 2

Status
Not open for further replies.

matpj

Technical User
Mar 28, 2001
687
GB
I have a group that returns several records.
I need to include a field that shows the increment between each value (the difference between one value and the previous record's value)


there is no difference function in the Running Total fields.
can anyone suggest anything?
 
I think what I need is just a way of calculating the percentage increase between the last record and first record,
as well as the total difference between first and last.

I used the Previous() function as suggested above, but i cant seem to find anything like a First() or Last() etc.
 
If your the values are in ascending or descending order, and all you need this information at group level then you should be able to use the min min() and max() functions

HTH

Gary Parker
MIS Data Analyst
Manchester, England
 
I wish it was that straight forward.

Basically the figures I am dealing with are budgeted hours.
It is grouped by project, and each record in that group is a revision to the project.
With each revision (record) the budgeted hours can increase OR decrease...

I need to somehow store the first record's 'budgethours' value in a variable and then for each record, calculate the percentage increase/decrease so that the last record will show the precentage difference from the FIRST record, NOT the previous one...

does this make sense?
 
Use an if statment to capture first and last records:

If OnFirstRecord.....
If OnLastRecord.....

Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
 
4 formulas needed, replace reset and difference formulas with these new ones.

Put tHis in the group header

Code:
//@Reset
WhilePrintingRecords;

BooleanVar Reset := True;
NumberVar SumDifference := 0;

Reset

Place these 3 on the details line

Code:
//@Difference
WhilePrintingRecords;

BooleanVar Reset;
NumberVar Difference ;
NumberVar SumDifference;
NumberVar PercentDifference;
NumberVar FirstValue;

If not Reset Then
    Difference := {MyTable.MyField} - Previous({MyTable.MyField})
Else
    (Difference := 0;
    Firstvalue := {MyTable.MyField});

SumDifference := SumDifference + Difference;
if FirstValue <> 0 Then PercentDifference := (SumDifference/FirstValue)*100 Else 0;

Reset := false;

Difference

Code:
//@SumDiffference
EvaluateAfter({@Difference});

NumberVar SumDifference;

Code:
@PercentDifference
EvaluateAfter({@Difference});

NumberVar PercentDifference;

This should give you what you need.

Gary Parker
MIS Data Analyst
Manchester, England
 
Thanks Gary,
that works perfectly!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top