Ok, I found a solution.
Of course, as soon as I got it finished, I hit preview one more time before I saved... and bam crw32.exe crashes. So I got to recreate it all over again :)
The solution:
I created a base formula, and placed this in the detail of the report and suppressed it:
//@Miles: Calc (Vehicle)
WhilePrintingRecords;
numbervar MinMiles;
numbervar MaxMiles;
select {@History: Repair Date}
case Maximum ({@History: Repair Date}, {vehfile.vehicle}) : MaxMiles := {@History: Repair Odometer}
case Minimum ({@History: Repair Date}, {vehfile.vehicle}) : MinMiles := {@History: Repair Odometer};
numbervar Miles := MaxMiles - MinMiles;
I have 3 groups, one by Facility, the next by Department, and third by the Vehicle #, as well as a grand total area.
So in order to get totals and a grand total, I have to have running totals for each of these.
So I created three additional formulas, one for each total:
//@Miles: Calc (Dept)
WhilePrintingRecords;
numbervar Miles;
numbervar TotalMilesDept := TotalMilesDept + Miles;
//@Miles: Calc (Fac)
WhilePrintingRecords;
numbervar Miles;
numbervar TotalMilesFac := TotalMilesFac + Miles;
//@Miles: Calc (Grand)
WhilePrintingRecords;
numbervar Miles;
numbervar TotalMiles := TotalMiles + Miles;
In order to reset the totals though, I had to put an initialize formula in the group headers, so it would reset on each new change of group. Here I hit a snag though, because I was repeating group headers on each page, so it was resetting the values in the middle of the groups. So I adjusted the formula to test the previous values to see if this was a new group or not.
//@Miles: Initialize (Fac)
WhilePrintingRecords;
if {VehFacility.div_mstr_num} <> Previous ({VehFacility.div_mstr_num})
then numbervar TotalMilesFac := 0;
//@Miles: Initialize (Dept)
WhilePrintingRecords;
if {vehfile.division} <> Previous ({vehfile.division})
then numbervar TotalMilesDept := 0;
On the vehicle, I had to preload the Min and Max Miles that the base calculation would be using as well, otherwise I'd end up with some bad totals on vehicles with only 1 repair record.
//@Miles: Initialize (Vehicle)
WhilePrintingRecords;
if ({vehfile.vehicle} <> Previous ({vehfile.vehicle}) or OnFirstRecord)
then
(numbervar MinMiles := {@History: Repair Odometer};
numbervar MaxMiles := {@History: Repair Odometer};
numbervar Miles := 0;)
Again, each of the init formulas went into the group headers, and work even if you repeat group headers on each page.
Now, I could have just put the calc formulas on the report in the subtotals area, except they were only displaying the last value for miles (even though the totalmilesx variable was listed last, very odd). I fixed it by copying each of the totals formulas into group footer #3 (lowest subgroup), but then the totals were adding the last set of miles twice (which makes sense, since the calc formula adds the miles to it's last value). So, I left the calc formulas in the group #3 footer, and made a final set of formulas that only display the totalmiles and placed these in each of their respective group footers.
//@Miles: Totals (Vehicle)
Whileprintingrecords;
numbervar Miles;
//@Miles: Totals (Dept)
WhilePrintingRecords;
numbervar TotalMilesDept;
//@Miles: Totals (Facility)
WhilePrintingRecords;
numbervar TotalMilesFac;
//@Miles: Totals (Grand)
WhilePrintingRecords;
numbervar TotalMiles;
So the overall structure looked something like this:
GH#1: @Miles: Initialize (Fac) (Suppressed)
GH#2: @Miles: Initialize (Dept) (Suppressed)
GH#3: @Miles: Initialize (Vehicle) (Suppressed)
D: @Miles: Calc (Vehicle) (Suppressed)
GF#3: @Miles: Totals (Vehicle) (Shown)
GF#3: @Miles: Calc (Dept) (Suppressed)
GF#3: @Miles: Calc (Fac) (Suppressed)
GF#3: @Miles: Calc (Grand) (Suppressed)
GF#2: @Miles: Totals (Dept) (Shown)
GF#1: @Miles: Totals (Fac) (Shown)
RF: @Miles: Totals (Grand) (Shown)