In this article, we will create a custom function or UDF to calculate the shift adherence time for the agents.
Raw data for this example consists of agent id along with login and logout time of each agent for the day. We have also defined the shift start and shift end time.
We have used custom function “TimeInterval” to calculate shift adherence time. This function takes four parameters as input.
Function TimeInterval(Login, Logout, ShiftStartTime, ShiftEndTime)
Shift start time is defined in the cell C7 and shift end time is defined in the cell C8.
To calculate shift adherence time, we have changed the login time to shift start time. If login time is early than shift start time, then shift start time will be considered as login time. If logout time is late than shift end time, then shift end time will be considered as logout time. Now, difference between the login and logout time will give shift adherence time.
Please follow below for the code
Option Explicit Function TimeInterval(Login As Double, Logout As Double, _ ShiftStartTime As Double, ShiftEndTime As Double) 'Checking whether login time is less than logout time If Login > Logout Then TimeInterval = "Login time should be less than logout time" Exit Function End If 'If login is less than shift start time then changing login time to shift start time If Login < ShiftStartTime Then Login = ShiftStartTime 'If logout is greater than shift end time then changing logout time to shift end time If Logout > ShiftEndTime Then Logout = ShiftEndTime TimeInterval = Logout - Login End Function
We would love to hear from you, do let us know how we can improve our work and make it better for you. Write to us at firstname.lastname@example.org
The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.