Crystal Report. Need to get average of number of days to complete work order Part two

J C
J C used Ask the Experts™
on
I closed out of my former question because I thought I had it worked out but it turns out I did not. I feel like I am close but the number being given as the average for the number of WORKING days is not correct. Here is a link to the original post/question.

http://www.experts-exchange.com/Database/Reporting_/Crystal_Reports/Q_27035326.html

I am using the formula I attached. It is supposed to return the number of working days between the PO Request Date and the Completion date. I named the formula above DaysDifference. I went to the Insert menu and selected Sum. I selected the @DaysDifference formula and set it to average.

I have a few vendors who only have one work order in the system. One vendor in particular had 10 working days between the Request Date and Completion Date if you subtract the weekends. The average was returned as 12.

Thanks for any insight you can provide!


//DaysDifference...Gives me the number of days
WhilePrintingRecords;
Global NumberVar TotalDaysToCompletion;
Global NumberVar WorkOrderCount;
Local NumberVar DaysDiff;
Global DateVar Array Holidays;
Local NumberVar FullDays;
Local NumberVar BankHolidays;
Local NumberVar Weekends;
Local NumberVar i;
Local Datevar StartDate := {WOHeader.RequestDate};//put your date here;
Local DateVar EndDate := {WOHeader.ComplDate};

    (
    //Count the number of full days between dates
    Fulldays := DateDiff ('d',StartDate,EndDate);

    //Count any holidays between dates
    For i := 1 to Ubound(holidays)
    Do
        If Holidays[i] >= StartDate and Holidays[i] <= EndDate Then
            BankHolidays := BankHolidays + 1;

    //Count any weekends between dates
    Weekends := DateDiff("ww", StartDate, EndDate, crsaturday) + 
                DateDiff("ww", StartDate, EndDate, crsunday)
    );

//Calculate Working days
DaysDiff := FullDays - Weekends - BankHolidays;
TotalDaysToCompletion := TotalDaysToCompletion + DaysDiff;
WorkOrderCount := WorkOrderCount  + 1;
DaysDiff

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
"One vendor in particular had 10 working days between the Request Date and Completion Date if you subtract the weekends. The average was returned as 12."

Are you saying that the difference on one record was correctly reported as 10 but the average for that one record comes out as 12?

Are you sure you are calculating the average of this formula field?
In fact, as it is currently written, you CANNOT calculate the average - so if you are getting a result you must be using a different field in the average calculation.

To be able to calculate the average of this field you need to remove the WhilePrintingRecords line.
Senior Consultant
Most Valuable Expert 2011
Top Expert 2013
Commented:
To get the average add a formula to the group footer

WhilePrintingRecords;
Global NumberVar TotalDaysToCompletion;
Global NumberVar WorkOrderCount;

If WorkOrderCount > 0 then
    TotalDaysToCompletion / WorkOrderCount
Else
    0

You also need to add a formula to the group header
WhilePrintingRecords;
Global NumberVar TotalDaysToCompletion;
Global NumberVar WorkOrderCount;
TotalDaysToCompletion := 0;
WorkOrderCount := 0;
""

mlmcc

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial