We help IT Professionals succeed at work.
Get Started

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

J C
J C asked
on
573 Views
Last Modified: 2012-05-11
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

Comment
Watch Question
Senior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE