troubleshooting Question

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

Avatar of J C
J CFlag for United States of America asked on
Crystal ReportsDB Reporting Tools
2 Comments1 Solution577 ViewsLast Modified:
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.

https://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

ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros