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

Calculate difference using first and last figure within a group 1

Status
Not open for further replies.

TerryFino

Technical User
Jun 11, 2002
8
0
0
AU
I am using Crystal Reports 9.

Is there a way of subtracting the last amount from the first amount within a group?

eg:
Group1
123 <-- first amount
124
345
789 <-- last amount
Group1 sub total = ??

Group2
137 <-- first amount
357
579
778 <-- last amount
Group2 sub total = ??

Your help would be most appreciated.

Thank you,
Terry
 
If the report is sorted by these values within the group, then you can create 1 formula to put in your group footer:

Maximum({table.field},{table.groupingfield}) - Minimum({table.field},{table.groupingfield})

Modify with your fields and place in the group footer.

Now, if they are not sorted by that field, then you need to use a couple of formulas:

//@First_Amount - place in the group header
whileprintingrecords;
numbervar first_amt := {table.field};

//@Sub_Total - place in the group footer
whileprintingrecords;
numbervar first_amt;
numbervar sub_total := {table.field} - first_amt;
first_amt := 0;
sub_total;

This second method should work in either scenario.

~Brian
 
Thank you that seems to work quite well.

Cheers
Terry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top