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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

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

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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