Forum Discussion

metcala's avatar
metcala
Helper III
3 years ago
Solved

Count active employees with missing timesheets

Hi

 

I have had a look around the forum for help but can't find any solutions that quite match my scenario.

 

I am looking to create a PowerBI matrix as below with 1 to show they were an active employee during that week and do not have an approved timesheet for that week:

 

Employee NameWeek ending - 2 April 2023Week ending - 9 April 2023...
Abc Def01...
Ghi Jkl11...

 

In terms of the data structure I have the following:

 

Employee table

Employee ID

Employee Name

Role ID

Start Date

End Date

 

Timesheet table

Timesheet ID

Employee ID

Period End

Total Hours

Status

 

Date table

Date linked to timesheet table (period end) and employee table (start date and end date)

 

I have tried creating a measure but am struggling to get it working.

 

Here is my current attempt which should just show the total approved hours.

 

 

Total Approved hours =
VAR _date = MAX('Timesheets'[Period End])
RETURN
CALCULATE(
   SUM('Timesheets'[Total Hours],
   FILTER(
      'Employees',
      'Employees'[Start Date] <= _date && 'Employees'[End Date] > _date
   ),
   FILTER(
      'Timesheets',
      'Timesheets'[Status] = "Approved"
   )
)

 

 

 

Any help would be greatly appreciated!

 

Thanks!

  • feel free to modify as needed.  And please don't use "moon dates".  Leave the end date blank if it is not known. Otherwise you create a lot of unnecessary entries in the calendar table.

4 Replies

  • Thanks for the response.

     

    For simplicity of the example data I will use months rather than weeks

     

    Employee table

     

    Employee IDEmployee NameRole IDStart DateEnd Date
    123John SmithA0011/1/20201/1/2099
    124Sally JonesA0021/1/202029/2/2020
    124Sally JonesA0031/3/20201/1/2099
    125Paul HowardA0041/4/202031/5/20

     

     

    Timesheet table

     

    Timesheet IDEmployee IDPeriodTotal HoursStatus
    100112331/1/20165Approved
    100212329/2/20160Approved
    100312331/3/20150Approved
    100412330/4/20170Approved
    100512331/5/20150Approved
    100612330/6/20160Pending
    100712431/1/20170Approved
    100812429/2/20165Approved
    100912431/3/20160Pending
    101012431/5/20150Approved
    101112430/6/20170Approved
    101212530/4/20150Approved
    101312531/5/20 160Approved

     

    Expected outcome

     

    To briefly explain the expected outcome:

     

    • If the employee is active and there is not an approved timesheet (i.e. no timesheet or a pending timesheet) there should be a 1
    • If the employee is active and there is an approved timesheet there should be a 0
    • If the employee is not active during that period it should remain blank

     

    Employee Name31/1/2029/2/2031/3/2030/4/2031/5/2030/6/20...
    John Smith000001 
    Sally Jones001100 
    Paul Howard   00  

     

    Thanks!

     

    • lbendlin's avatar
      lbendlin
      Super User

      feel free to modify as needed.  And please don't use "moon dates".  Leave the end date blank if it is not known. Otherwise you create a lot of unnecessary entries in the calendar table.

      • metcala's avatar
        metcala
        Helper III

        Thank you so much! That is exactly what I was after.

         

        Really appreciate you taking the time to help me out!