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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

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])

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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])

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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