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!

Formula issue in footer

Status
Not open for further replies.

dz0k52

Technical User
Jul 21, 2003
32
0
0
CA
I am using Crystal 8.5 with an Oracle 9 database. I am having trouble with a formula which is carrying data into the footer and casuing my result to be inaccurate.
The report groups all records from one peice of equipment for a particular date range of workorders.
The first formula is placed in the details and suppressed, it is: Time between last failure
if ({WORKORDER.ACTSTART} >= previous({WORKORDER.ACTFINISH}))then((DateDiff ("n", previous({WORKORDER.ACTFINISH}),{WORKORDER.ACTSTART} ))/60)

This just establishes whether or not the workorder started before the last one was finished.
The next formula (placed in details)is: @Count Workorders
if {@Time between last failure} > 0
and {WORKORDER.WORKTYPE} = 'EM'
then 1

This counts the workorder as a failure if the workorder started after previous one and it is a worktype EM.
Last formula (placed in group footer): @sum workorders
WhilePrintingRecords;
numbervar countwo:=tonumber({@Count Workorders});
numbervar tothrs:= tothrs + countwo;

Since the summary function does not work on @Count Workorders, this was the only way to display the total count of failures in that particular date range.

When the last record in the report is a CM (<> EM) the report is accurate. When the last record in the report is an EM, it counts one more record. I placed a copy of
@Count Workorders in the footer and it looks as though when the last record is an EM, it is counting the footer as another record. How do I limit @sum workorders to not count the data in the footer as a record??


 
Create one formula for the detail section:

whileprintingrecords;
numbervar diff := 0;
numbervar cnt;

if {WORKORDER.ACTSTART} >= previous({WORKORDER.ACTFINISH})then
diff := DateDiff ("n", previous({WORKORDER.ACTFINISH}),{WORKORDER.ACTSTART})/60;
if diff > 0 and
{WORKORDER.WORKTYPE} = 'EM' then
cnt := cnt + 1;

Then in the group footer, use this formula:

whileprintingrecords;
numbervar cnt;
numbervar sumcnt;
sumcnt := sumcnt + cnt;
cnt

In the group header use:
whileprintingrecords;
numbervar cnt;
if not inrepeatedgroupheader then
cnt := 0;

For a summary in the report footer, use:

whileprintingrecords;
numbervar sumcnt;

-LB
 
The results in the footer are perfect, I have just one more issue.If the first record of the report is an 'EM', there is no previous record to do a date diff, so it is not counting it. I can't seem to figure out the proper syntax to count the first record if it is an EM.
I tried something like
if isnull(diff) and {WORKORDER.WORKTYPE} = 'EM' then
cnt := cnt + 1; else.........
but it doesn't like the syntax (looking for a field after the isnull).

 
Change the clause to:

if
(
onfirstrecord or
diff > 0
) and
{WORKORDER.WORKTYPE} = 'EM' then
cnt := cnt + 1;

-LB

 
Still null on first record. I am trying this:
whileprintingrecords;
numbervar diff:= 0;
numbervar cnt;

if {WORKORDER.ACTSTART} >= previous({WORKORDER.ACTFINISH})then
diff := DateDiff ("n", previous({WORKORDER.ACTFINISH}),{WORKORDER.ACTSTART})/60;

if (onfirstrecord or
diff > 0) and
{WORKORDER.WORKTYPE} = 'EM' then
cnt := cnt + 1;

 
Observation
When I rearrange and use the following as my formula, I get the expected "1" when the first record is an EM. When I remove the // to incorporate the rest of the formula the result for the first record changes to "0".
whileprintingrecords;
numbervar diff:= 0;
numbervar cnt;

if onfirstrecord and {WORKORDER.WORKTYPE} = 'EM'
then cnt :=1
//else if {WORKORDER.ACTSTART} >= previous({WORKORDER.ACTFINISH})then
//diff := DateDiff ("n", previous({WORKORDER.ACTFINISH}),{WORKORDER.ACTSTART})/60;
//if diff > 0 and
//{WORKORDER.WORKTYPE} = 'EM' then
//cnt := cnt + 1;
 
Change the formula to:

whileprintingrecords;
numbervar diff:= 0;
numbervar cnt;

if [red]not onfirstrecord and[/red]
{WORKORDER.ACTSTART} >= previous({WORKORDER.ACTFINISH})then
diff := DateDiff ("n", previous({WORKORDER.ACTFINISH}),{WORKORDER.ACTSTART})/60;

if (onfirstrecord or
diff > 0) and
{WORKORDER.WORKTYPE} = 'EM' then
cnt := cnt + 1;

-LB
 
Absolutely Perfect,
Thanks once again Lbass :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top