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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. 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])

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.