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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
OCBB_SFAFPandA
Resolver I
Resolver I

How to calculate working hours per day per employee

Hello,

 

I have data that includes

DateEmp IdHrs
6/20/22123453
6/20/22123458

 

I need to agregate the data to sum up Emp ID hours for the same day, and flag anything over 8 hrs as OT. Like so

DateEmp IDTotal HrsReg hrsOT 
6/20/22123451183

 

This would ideally aggregate to a higher level that does not show employee ID's and shows by locations. 

Any help or resources that will help?

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@OCBB_SFAFPandA , Create two measures like

 

Std hours  =

sumx(summarize(Table, Table[Date], Table[Emp ID], "_1", Sum(Table[Hrs]) ), if([_1]> 8,8, [_1]) )

 

Overtime =

sumx(summarize(Table, Table[Date], Table[Emp ID], "_1", Sum(Table[Hrs]) ), if([_1]> 8, [_1]-8,0) )

 

Total hours = Sum(Table[Hrs])

View solution in original post

jorge_olivares
Frequent Visitor

Hey @OCBB_SFAFPandA !

 

I saw you already got a reply from @amitchandak using measures.

 

I am attaching a table and the dax code for the calculated table. Hope it helps!

 

Table Name = HoursWorkedTab

 

Date  -  EmpID  -  HoursWorked  -  OTHours

Friday, June 17, 20221250
Friday, June 17, 2022530
Friday, June 17, 2022120.550
Friday, June 17, 2022530
Friday, June 17, 2022891
Friday, June 17, 20221260
Monday, June 20, 2022120.250
Monday, June 20, 20221210
Monday, June 20, 2022540
Monday, June 20, 2022860
Monday, June 20, 2022810
Monday, June 20, 2022850
Tuesday, June 21, 202287.50
Tuesday, June 21, 20221250
Tuesday, June 21, 2022570
Tuesday, June 21, 20221210
Tuesday, June 21, 2022510
Tuesday, June 21, 202250.30
Tuesday, June 21, 20221240

 

SummarizedHours =

SUMMARIZE(

HoursWorkedTab,

HoursWorkedTab[Date],

HoursWorkedTab[EmpID],

"HoursWorked",

SUM(HoursWorkedTab[HoursWorked]),

"RegularHours",

SWITCH(TRUE,

SUM(HoursWorkedTab[HoursWorked]) <= 8, SUM(HoursWorkedTab[HoursWorked]),

SUM(HoursWorkedTab[HoursWorked]) > 8, 8),

"OTHours",

SWITCH(TRUE,

SUM(HoursWorkedTab[HoursWorked]) <= 8, 0,

SUM(HoursWorkedTab[HoursWorked]) > 8, SUM(HoursWorkedTab[HoursWorked]) - 8))

 

jorge_olivares_0-1655867738422.png

 

 

 

View solution in original post

4 REPLIES 4
jorge_olivares
Frequent Visitor

Hey @OCBB_SFAFPandA !

 

I saw you already got a reply from @amitchandak using measures.

 

I am attaching a table and the dax code for the calculated table. Hope it helps!

 

Table Name = HoursWorkedTab

 

Date  -  EmpID  -  HoursWorked  -  OTHours

Friday, June 17, 20221250
Friday, June 17, 2022530
Friday, June 17, 2022120.550
Friday, June 17, 2022530
Friday, June 17, 2022891
Friday, June 17, 20221260
Monday, June 20, 2022120.250
Monday, June 20, 20221210
Monday, June 20, 2022540
Monday, June 20, 2022860
Monday, June 20, 2022810
Monday, June 20, 2022850
Tuesday, June 21, 202287.50
Tuesday, June 21, 20221250
Tuesday, June 21, 2022570
Tuesday, June 21, 20221210
Tuesday, June 21, 2022510
Tuesday, June 21, 202250.30
Tuesday, June 21, 20221240

 

SummarizedHours =

SUMMARIZE(

HoursWorkedTab,

HoursWorkedTab[Date],

HoursWorkedTab[EmpID],

"HoursWorked",

SUM(HoursWorkedTab[HoursWorked]),

"RegularHours",

SWITCH(TRUE,

SUM(HoursWorkedTab[HoursWorked]) <= 8, SUM(HoursWorkedTab[HoursWorked]),

SUM(HoursWorkedTab[HoursWorked]) > 8, 8),

"OTHours",

SWITCH(TRUE,

SUM(HoursWorkedTab[HoursWorked]) <= 8, 0,

SUM(HoursWorkedTab[HoursWorked]) > 8, SUM(HoursWorkedTab[HoursWorked]) - 8))

 

jorge_olivares_0-1655867738422.png

 

 

 

Thanks for the help @jorge_olivares!

amitchandak
Super User
Super User

@OCBB_SFAFPandA , Create two measures like

 

Std hours  =

sumx(summarize(Table, Table[Date], Table[Emp ID], "_1", Sum(Table[Hrs]) ), if([_1]> 8,8, [_1]) )

 

Overtime =

sumx(summarize(Table, Table[Date], Table[Emp ID], "_1", Sum(Table[Hrs]) ), if([_1]> 8, [_1]-8,0) )

 

Total hours = Sum(Table[Hrs])

Thanks @amitchandak !

 

This worked perfectly!  the _1 is the var name you gave the  summary total?

 

if I need a formula to mark any hours worked over 40 hours as OT for the week, how would I do that without dbl counting hours for OT? 

 

You've helped me im previous threads and you are very knowledgeable. I followed your channel and will learn from your videos. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors