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

Subtract First Record from the Last Record 3

Status
Not open for further replies.

mmck1964

Technical User
Jul 12, 2001
104
US
I have report grouped by ID number and pulled in a date range of data into the detail section of the report. Below is an example of the data: {date} and {reading}

9/01/2011 18900
9/02/2011 18991
9/03/2011 19025
and so on until---
9/30/2011 20528
10/1/2011 20575

I would like to subtract the 10/1/2011 reading from the 9/01/2011 reading. How can I do this for each grouped ID number?
Thanks
 
If the values are always increasing (and not going up and down), you can use a formula like this:

maximum({table.reading},{table.ID})-minimum({table.reading},{table.ID})

-LB
 
In most cases, the values should be increasing, but not always. However, the dates will always be increasing for each value. I would like to see if there is a formula that would find the first date and the last date, then subtract the value associated with the first date from the value associated with the last date.
 
Then create formulas like this:

//{@readings} to be placed in the detail section and suppressed:
whileprintingrecords;
numbervar first;
numbervar last;
if {table.date} = minimum({table.date},{table.ID}) then
first := {table.reading};
if {table.date} = maximum({table.date},{table.ID}) then
last := {table.reading};

//(@displaydiff} to be placed in the group footer:
whileprintingrecords;
numbervar first;
numbervar last;
last-first

//{@reset} to be placed in the ID group header and suppressed:
whileprintingrecords;
numbervar first;
numbervar last;
if not inrepeatedgroupheader then (
first := 0;
last := 0
);

-LB
 
Now for another question. Is there a way to take value calculated in the Group Footer (Last - First) and sum all of those values in the Report Footer?
 
Change the group footer {@display} to:

whileprintingrecords;
numbervar first;
numbervar last;
numbervar diff := last-first;
numbervar sumdiff := sumdiff + diff;
diff

Then in the report footer add a formula {@sumdiff}:

whileprintingrecords;
numbervar sumdiff;

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top