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

Shared DateTimeVar Subreport & Average Process Times 2

Status
Not open for further replies.

bluraz

MIS
Aug 18, 2005
32
US
Crystal XI

I am trying to calculate an average time.

I am sharing a datetimevar from a subreport to the main, called {@MainYardDate}:

WhilePrintingRecords;
Shared DateTimeVar SubYardDate ;
SubYardDate

Using the shared variable, I have created the following formula to calculate the datediff {@TimePerShipment}:

If datediff ('d', {@MainYardDate},{ACTUALRECEIVEDSHIPPEDDATETIME})> 6 or
dayofweek ({@MainYardDate}) > dayofweek ({ACTUALRECEIVEDSHIPPEDDATETIME})then
numbervar diff:= datediff('s',{@MainYardDate},{ACTUALRECEIVEDSHIPPEDDATETIME})/3600 - 30
else numbervar diff:= datediff ('s', {@MainYardDate},{ACTUALRECEIVEDSHIPPEDDATETIME})/3600

When I try to save the following formula to caclulate the Average "TimePerShipment", I receive an error message that {@TimePerShipment} cannot be summarized.

NumberVar nbrTime := Average ({@TimePerShipment}, {IDMASTER_Consignee.IDENTITYID});
NumberVar nbrHour := Truncate(nbrTime);
NumberVar nbrHold := (nbrTime-nbrHour)*100;
nbrHold := (60*nbrHold)/100;
NumberVar nbrMinute := Truncate(nbrHold);
nbrHold:= (nbrHold-nbrMinute)*100;
NumberVar nbrSecond := Truncate(nbrHold*60)/100;
stringvar Output :=
ToText(nbrHour,0,"") + ":" + ToText(nbrMinute,0,"") + ":" + ToText(nbrSecond,0,"");
if instr(Output,"-") > 0 then
"(" & replace(Output,"-","") & ")"
else
Output

Why am I not allowed to summarize the {@TimePerShipment}? Is there a work-around for what I am trying to accomplish?

Thanks in advance for any help or suggestions!

Amy

 
The problem is the date field coming from the shared variable. Shared variables and variables used whileprintingrecords cannot be summarized with inserted summaries. Instead you would have to use a variable to accumulate {@TimePerShipment} and also to count the number of instances. You can then calculate the average in the report footer. Something like:

//{@accum} to be placed in the detail section:
Whileprintingrecords;
numbervar diff;
If datediff ('d', {@MainYardDate},{ACTUALRECEIVEDSHIPPEDDATETIME})> 6 or
dayofweek ({@MainYardDate}) > dayofweek ({ACTUALRECEIVEDSHIPPEDDATETIME})then
diff:= datediff('s',{@MainYardDate},{ACTUALRECEIVEDSHIPPEDDATETIME})/3600 - 30 else
diff:= datediff ('s', {@MainYardDate},{ACTUALRECEIVEDSHIPPEDDATETIME})/3600;
numbervar sumdiff := sumdiff + diff;
numbervar cnt := cnt + 1;

Then in the group footer use a formula like:

whileprintingrecords;
numbervar sumdiff;
numbervar cnt;
NumberVar nbrTime := sumdiff/cnt;
NumberVar nbrHour := Truncate(nbrTime);
NumberVar nbrHold := (nbrTime-nbrHour)*100;
nbrHold := (60*nbrHold)/100;
NumberVar nbrMinute := Truncate(nbrHold);
nbrHold:= (nbrHold-nbrMinute)*100;
NumberVar nbrSecond := Truncate(nbrHold*60)/100;
stringvar Output :=
ToText(nbrHour,0,"") + ":" + ToText(nbrMinute,0,"") + ":" + ToText(nbrSecond,0,"");
if instr(Output,"-") > 0 then
"(" & replace(Output,"-","") & ")"
else
Output

You will need a reset in the group header:
whileprintingrecords;
numbervar sumdiff;
numbervar cnt;
if not inrepeatedgroupheader then(
sumdiff := 0;
cnt := 0
);

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top