Hi there,
I hve altered Ken's working days formula (thanks Ken!) to suit my report however instead of returning the absence days as required, I am getting zero vaules returned and I can't see why.. as usual, any help much appreciated, formula attached below:
numberVar TotalAbs;
DateVar Begin := { X | SW_0009a_Monthly_Abs_By_Dept.BEGIN_DT};
DateVar Return := { X | SW_0009a_Monthly_Abs_By_Dept.RETURN_DT};
numberVar AbWeeks1;
numberVar AbWeeks2;
numberVar AbWeeks3;
numberVar AbWeeks4;
numberVar AbDays1;
numberVar AbDays2;
numberVar AbDays3;
numberVar AbDays4;
//Calcs for each of 4 absence instances below:
numberVar DayReturn := Day( Return );
numberVar DayBegin := Day( Begin );
AbWeeks1:= Truncate( ( DayReturn - DayOfWeek( Return ) + 1- ( DayBegin - DayOfWeek( Begin ) + 1 ) ) / 7 ) * 5;
AbDays1 := DayofWeek( Return ) - DayOfWeek( Begin ) + 1; //adjusts first and last week depending on when in the wk you start & end
AbWeeks2:= Truncate( ( DayReturn - DayOfWeek( Return ) + 1 ) / 7 ) * 5;
AbDays2:= DayofWeek( Return ) - DayOfWeek( Begin ) + 1;
DateVar EndOfJan := Date( Year ( CurrentDateTime ), 01, 31 );
DateVar StartOfJan := Date( Year ( CurrentDateTime ), 01, 01 );
AbWeeks3:= Truncate( ( 31- DayOfWeek( EndOfJan ) + 1 - ( DayBegin - DayOfWeek( Begin ) + 1 ) ) / 7 ) * 5;
AbDays3:= DayOfWeek( EndOfJan ) - DayOfWeek( Begin ) +1;
AbWeeks4:= Truncate ( (31 - DayOfWeek( EndOfJan ) + 1 - ( 1- DayOfWeek( StartOfJan ) + 1 ) ) / 7 ) * 5;
AbDays4:= DayOfWeek( EndOfJan ) - DayOfWeek( StartOfJan ) +1;
numberVar HolsJan := 1; //hogmanay holiday
numberVar HolsDec:= 2; //xmas, boxing
//for absences in January in the current year
IF
Month(Begin)= 1 AND
Month(Return) = 1 AND
Year(Begin) = Year (CurrentDateTime) AND
Year(Return) = Year (CurrentDateTime) THEN
TotalAbs = AbWeeks1 + AbDays1;
//for absences ending in January this year which have started prior to Jan this year deducting 1 day for new Years Holiday ( therefore began outwith current year)
IF
Month(Return) = 1 AND
Year(Return) = Year (CurrentDateTime) AND
Year(Begin) < Year (CurrentDateTime) THEN
TotalAbs = AbWeeks2 + AbDays2 - HolsJan;
// Absences in Jan this year which carry into Feb/subsequent months this year
IF
Month(Begin) = 1 AND
Year(Begin) = Year (CurrentDateTime) AND
Year(Return) = Year (CurrentDateTime) AND
Month(Return) > 1 THEN
IF begin > Date (Year (CurrentDateTime),01,01 )
THEN
TotalAbs:= AbWeeks3+ AbDays3
ELSE
TotalAbs:= AbWeeks3+ AbDays3 - HolsJan
//Absences in Jan this year which start outwith Jan this year and finish outwith Jan this year
ELSE
IF Begin < Date (Year (CurrentDateTime),01,01 )
AND Year(Return) = Year(CurrentDateTime)
AND month(Return) >1
THEN
TotalAbs:= AbWeeks4 + AbDays4 - HolsJan;
I hve altered Ken's working days formula (thanks Ken!) to suit my report however instead of returning the absence days as required, I am getting zero vaules returned and I can't see why.. as usual, any help much appreciated, formula attached below:
numberVar TotalAbs;
DateVar Begin := { X | SW_0009a_Monthly_Abs_By_Dept.BEGIN_DT};
DateVar Return := { X | SW_0009a_Monthly_Abs_By_Dept.RETURN_DT};
numberVar AbWeeks1;
numberVar AbWeeks2;
numberVar AbWeeks3;
numberVar AbWeeks4;
numberVar AbDays1;
numberVar AbDays2;
numberVar AbDays3;
numberVar AbDays4;
//Calcs for each of 4 absence instances below:
numberVar DayReturn := Day( Return );
numberVar DayBegin := Day( Begin );
AbWeeks1:= Truncate( ( DayReturn - DayOfWeek( Return ) + 1- ( DayBegin - DayOfWeek( Begin ) + 1 ) ) / 7 ) * 5;
AbDays1 := DayofWeek( Return ) - DayOfWeek( Begin ) + 1; //adjusts first and last week depending on when in the wk you start & end
AbWeeks2:= Truncate( ( DayReturn - DayOfWeek( Return ) + 1 ) / 7 ) * 5;
AbDays2:= DayofWeek( Return ) - DayOfWeek( Begin ) + 1;
DateVar EndOfJan := Date( Year ( CurrentDateTime ), 01, 31 );
DateVar StartOfJan := Date( Year ( CurrentDateTime ), 01, 01 );
AbWeeks3:= Truncate( ( 31- DayOfWeek( EndOfJan ) + 1 - ( DayBegin - DayOfWeek( Begin ) + 1 ) ) / 7 ) * 5;
AbDays3:= DayOfWeek( EndOfJan ) - DayOfWeek( Begin ) +1;
AbWeeks4:= Truncate ( (31 - DayOfWeek( EndOfJan ) + 1 - ( 1- DayOfWeek( StartOfJan ) + 1 ) ) / 7 ) * 5;
AbDays4:= DayOfWeek( EndOfJan ) - DayOfWeek( StartOfJan ) +1;
numberVar HolsJan := 1; //hogmanay holiday
numberVar HolsDec:= 2; //xmas, boxing
//for absences in January in the current year
IF
Month(Begin)= 1 AND
Month(Return) = 1 AND
Year(Begin) = Year (CurrentDateTime) AND
Year(Return) = Year (CurrentDateTime) THEN
TotalAbs = AbWeeks1 + AbDays1;
//for absences ending in January this year which have started prior to Jan this year deducting 1 day for new Years Holiday ( therefore began outwith current year)
IF
Month(Return) = 1 AND
Year(Return) = Year (CurrentDateTime) AND
Year(Begin) < Year (CurrentDateTime) THEN
TotalAbs = AbWeeks2 + AbDays2 - HolsJan;
// Absences in Jan this year which carry into Feb/subsequent months this year
IF
Month(Begin) = 1 AND
Year(Begin) = Year (CurrentDateTime) AND
Year(Return) = Year (CurrentDateTime) AND
Month(Return) > 1 THEN
IF begin > Date (Year (CurrentDateTime),01,01 )
THEN
TotalAbs:= AbWeeks3+ AbDays3
ELSE
TotalAbs:= AbWeeks3+ AbDays3 - HolsJan
//Absences in Jan this year which start outwith Jan this year and finish outwith Jan this year
ELSE
IF Begin < Date (Year (CurrentDateTime),01,01 )
AND Year(Return) = Year(CurrentDateTime)
AND month(Return) >1
THEN
TotalAbs:= AbWeeks4 + AbDays4 - HolsJan;