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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

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

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

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
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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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