Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grouping by a formula

Status
Not open for further replies.

falconstooth

IS-IT--Management
Dec 12, 2003
2
US
I have the following formula which is designed to determine how many workdays a person has taken off by calculating the difference between "DateOff" and "ReturnDate" fields. The formula takes into consideration weekends and specified holidays. The problem I'm having is that I cannot create a summary that will add up all of a person's days off. I need a "Total Days Off" field in the report, but cannot seem to accomplish it.
Any ideas would be much appreciated.

WhilePrintingRecords;
DateVar Start:= Date({CallOffHistEmp.DateOff});
DateVar End:= Date({CallOffHistEmp.ReturnDate});
NumberVar Weeks;
NumberVar Days;
NumberVar Hol:=0;

Weeks:= (Truncate(End-DayofWeek(End)+1-(Start-DayofWeek(Start)+1))/7)*5;

Days:=DayofWeek(End)-DayofWeek(Start)+1
+(if DayofWeek(Start)=1 Then-1 Else 0)
+(if DayofWeek(End)=7 Then -1 Else 0);

If Date(2004,08,23) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2004,08,24) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2004,09,06) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2004,10,22) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2004,11,24) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2004,11,25) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2004,11,26) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2004,12,20) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2004,12,21) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2004,12,22) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2004,12,23) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2004,12,24) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2004,12,27) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2004,12,28) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2004,12,29) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2004,12,30) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2004,12,31) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2005,01,17) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2005,02,18) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2005,02,21) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2005,03,25) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2005,03,28) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2005,03,29) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2005,03,30) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2005,03,31) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2005,04,01) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2005,04,29) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;
If Date(2005,05,30) in Start to End Then Hol:= Hol+1 Else Hol:= Hol;

Weeks+Days+Hol-1
(formula base provided by Ken Hamady)
 
How are you grouping your report? If you are grouping by employee, put this in a formula in the employee header:

Code:
Whileprintingrecords;
Global Numbervar EmpDays;
EmpDays := 0;

Then add
Code:
 Global Numbervar EmpDays;
to the top of your formula, and at the bottom (assuming the last line here is what you want to add):
Code:
EmpDays := EmpDays + (Weeks+Days+Hol-1);
This will give you a running total. Then, in the employee footer, add a formula to print out the current total:
Code:
Global Numbervar EmpDays;
EmpDays;

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top