Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Shahzad_Ahsan
Creator III
Creator III

Get Employee count who are continuously absent for 10 or more days

Hi

I need to count employees who are continuously absent for 10 or more days. Excluding weekends, here weekend days are Fri and Sat

Sample data and qvf is attached. Please update in this qvf .


This sample data contains total 5 employees out of which 2 are absent continuously for 10 or more days. Those are,1001 and 1004. I want measure expression that count these 2 employee.

14 Replies
christophebrault
Specialist
Specialist

Hi,

I don't have so much time, but is this script working as desired ?

TEMP:

LOAD

    EmpCode,Month(Att_Date) as Month,

    Att_Date,num(weekday(Att_Date)) as NoDay,

    Absent

FROM [lib://Attendance/Attendance.xlsx]

(ooxml, embedded labels, table is Sheet1);



FINAL:

LOAD * ,

    if(EmpCode=Peek(EmpCode) ,

     If(NoDay<5    and Absent='Y',Peek(AbsDuration)+1,

     If(NoDay<5    and (Absent='N' or peek(Month)<>Month),0, Peek(AbsDuration))),0)

     as AbsDuration



Resident TEMP

order by EmpCode,Att_Date asc;



drop table TEMP;

Inscrivez vous à ma Newletter Qlik
DoNotMissQlik- Connect with me on Linkedin
Shahzad_Ahsan
Creator III
Creator III
Author

No, This is not working.

Shahzad_Ahsan
Creator III
Creator III
Author

I need something like this

EmpCodeDateAbsenceAbsDuration(Old)AbsDuration(Needed)
100527-May-2018Y11
100528-May-2018Y22
100529-May-2018Y33
100530-May-2018Y44
100531-May-2018Y55
100501-Jun-2018N55
100502-Jun-2018N55
100503-Jun-2018Y61
100504-Jun-2018Y72
100505-Jun-2018Y83
100506-Jun-2018Y94
100507-Jun-2018Y105
Shahzad_Ahsan
Creator III
Creator III
Author

Finally I achieved what I needed

TEMP:

LOAD

    EmpCode,Month(Att_Date) as Month1,

    Att_Date,num(weekday(Att_Date)) as NoDay,

    Absent

FROM [lib://Attendance/Attendance.xlsx]

(ooxml, embedded labels, table is Sheet1);

FINAL:

LOAD * ,

    if(EmpCode=Peek(EmpCode) ,if(Month1=peek(Month1),

     If(NoDay<5 and Absent='Y' ,Peek(AbsDuration)+1,

     If(NoDay<5 and Absent='N' ,0, Peek(AbsDuration))),0),0)

     as AbsDuration

Resident TEMP

order by EmpCode,Att_Date asc;

drop table TEMP;

Mr_H_Huang
Contributor III
Contributor III

@Shahzad_Ahsan Thank you very much for your final solution with re-set syntax. It has been my very helpful to my case.

I would like to share my simlar result of the working script. I have modifed mine based on your solution. My user requirement was:
1, there are many different roster, each has has different working date and non-working date pattern, a employee could work on one or multiple working pattern during his long employment. 

2, If an employee absence continued for 11 days or more of their working dates , it is flaged as long term absence. 

3, Non-working date not treated as absense, but will carry on to the next absence, untill the employee come back to work. It means re-set when employee back to work.

4, If employee_working_hours  > 0, it means it is a working date. If employee_working_hours = 0, it means it is a non-working date. absence_emp_no means the employee number was absence on that date. 

5, Be aware the order by is very import to sort the absence duration.

Charleston_Juan_0-1698498152348.png

 

employee_date_with_absence_temp:
LOAD
absence_emp_no,
absence_reg_time,
IF(employee_working_hours >0 AND NOT ISNULL(absence_emp_no), 1, 
IF(employee_working_hours >0 AND ISNULL(absence_emp_no), 2 ,
IF((employee_working_hours = 0 OR ISNULL(employee_working_hours)) AND NOT ISNULL(absence_emp_no), 3, 0

)
)
) AS flag_type,

employee_no,
roster_ref,
employee_working_hours,
employee_working_date

RESIDENT employee_date_final
ORDER BY employee_no ASC, employee_working_date ASC;
DROP TABLE employee_date_final;


employee_date_with_absence:
LOAD
absence_emp_no,
absence_reg_time,
flag_type,

IF(employee_no=PEEK(employee_no), //if employee_no the same as the employee_no above
      IF( flag_type=1, PEEK(absence_duration)+1, //if the date is working date, and employee absence, absence_duration plus 1 day
      IF(flag_type=3 OR flag_type=0, PEEK(absence_duration), //if the date is non-working date, absence_duration remain unchange 
      IF(flag_type=2, 0, PEEK(absence_duration) )//if the employee worked on a working date during absece, absence_duration reset to 0, otherwise absence_duration remian unchange
      )),0)//All other cases re-set to zero
     AS absence_duration,

IF(
IF(employee_no=PEEK(employee_no), //if employee_no the same as the employee_no above
      IF( flag_type=1, PEEK(absence_duration)+1, //if the date is working date, and employee absence, absence_duration plus 1 day
      IF(flag_type=3 OR flag_type=0, PEEK(absence_duration), //if the date is non-working date, absence_duration remain unchange 
      IF(flag_type=2, 0, PEEK(absence_duration) )//if the employee worked on a working date during absece, absence_duration reset to 0, otherwise absence_duration remian unchange
      )),0)//All other cases re-set to zero
      >=11,1,0)
     AS long_term_absence_flag,

employee_no,
roster_ref,
employee_working_hours AS roster_working_hours,
employee_working_date AS roster_working_date

RESIDENT employee_date_with_absence_temp
ORDER BY employee_no ASC, employee_working_date ASC;
DROP TABLE employee_date_with_absence_temp;