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!

Prevoius maximum 1

Status
Not open for further replies.

sbf

Technical User
Dec 11, 2000
14
DK
Hi Everyone, I need help
CRW 8.5 on SQL Server.
I have the following data set:

Start End Lane RT_NR Diff (NR)
10,00 17,00 NR 17
14,00 15,00 NR 17 14-17= -3
16,00 19,00 NL 17
18,00 20,00 NR 20 18-17= 1
21,00 24,00 NL 20
23,00 25,00 NR 25 23-20= 3
23,00 37,00 NL 25
24,00 28,00 NR 28 24–25= -1

For each Lane I want to calculate the difference between Start and the previous maximum End value. (Only shown for NR in above example)

For the Diff calculation I need the previous value of the running total for Lane NR (RT_NR sum on: End, type: maximum, evaluate use formular: Lane = "NR")
Is that possible?


Thanks in advance, kla

 
Try the following:

whileprintingrecords;
numbervar maxend;
numbervar counter;
numbervar diff;

if previous({table.lane}) = "NR" and
previous({table.end}) >= maxend then
maxend := previous({table.end}) else
maxend := maxend;

if {table.lane} = "NR" then
(counter := counter + 1;
if counter > 1 then
diff := {table.start} - maxend);

-LB
 
Thanks Ibass, it works perfect.

My example represents data for one day. I have data for more days and are grouping by day.
I have tried to reset the maxend value in the Group Header with:

@reset
whileprintingrecords;
numbervar maxend:=0;

But the calculation continues with the maximum maxend value from the previous day. How do I reset ?

kla
 
First, change the formula to:

whileprintingrecords;
numbervar maxend;
numbervar counter;
numbervar diff;

if onfirstrecord then
maxend := {table.end} else
if previous({table.lane}) = "NR" and
previous({table.end}) >= maxend then
maxend := previous({table.end}) else
maxend := maxend;

if {table.lane} = "NR" then
(counter := counter + 1;
if counter > 1 then
diff := {table.start} - maxend);

Then for the reset formula to place in the group (day) header use:

whileprintingrecords;
numbervar counter := 0;
numbervar maxend := 0;

-LB

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top