Avatar of J C
J CFlag for United States of America

asked on 

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

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/questions/27035326/Crystal-Report-Need-to-get-average-of-number-of-days-to-complete-work-order.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

Crystal ReportsDB Reporting Tools

Avatar of undefined
Last Comment
Mike McCracken
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

"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.
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Crystal Reports
Crystal Reports

Crystal Reports is a business intelligence application from SAP SE. It is used to graphically design data connections and report layouts from a wide range of data sources including Excel spreadsheets, Oracle, SQL Server databases and Access databases, BusinessObjects Enterprise business views, and local file-system information. Report designers can place fields from these sources on the report design surface, and can also deploy them in custom formulas (using either BASIC or Crystal's own syntax), which are then placed on the design surface. Crystal Reports also supports subreports, graphing, and a limited amount of GIS functionality.

36K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo