March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hello,
I have data that includes
Date | Emp Id | Hrs |
6/20/22 | 12345 | 3 |
6/20/22 | 12345 | 8 |
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
Date | Emp ID | Total Hrs | Reg hrs | OT |
6/20/22 | 12345 | 11 | 8 | 3 |
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?
Solved! Go to Solution.
@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])
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, 2022 | 12 | 5 | 0 |
Friday, June 17, 2022 | 5 | 3 | 0 |
Friday, June 17, 2022 | 12 | 0.55 | 0 |
Friday, June 17, 2022 | 5 | 3 | 0 |
Friday, June 17, 2022 | 8 | 9 | 1 |
Friday, June 17, 2022 | 12 | 6 | 0 |
Monday, June 20, 2022 | 12 | 0.25 | 0 |
Monday, June 20, 2022 | 12 | 1 | 0 |
Monday, June 20, 2022 | 5 | 4 | 0 |
Monday, June 20, 2022 | 8 | 6 | 0 |
Monday, June 20, 2022 | 8 | 1 | 0 |
Monday, June 20, 2022 | 8 | 5 | 0 |
Tuesday, June 21, 2022 | 8 | 7.5 | 0 |
Tuesday, June 21, 2022 | 12 | 5 | 0 |
Tuesday, June 21, 2022 | 5 | 7 | 0 |
Tuesday, June 21, 2022 | 12 | 1 | 0 |
Tuesday, June 21, 2022 | 5 | 1 | 0 |
Tuesday, June 21, 2022 | 5 | 0.3 | 0 |
Tuesday, June 21, 2022 | 12 | 4 | 0 |
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))
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, 2022 | 12 | 5 | 0 |
Friday, June 17, 2022 | 5 | 3 | 0 |
Friday, June 17, 2022 | 12 | 0.55 | 0 |
Friday, June 17, 2022 | 5 | 3 | 0 |
Friday, June 17, 2022 | 8 | 9 | 1 |
Friday, June 17, 2022 | 12 | 6 | 0 |
Monday, June 20, 2022 | 12 | 0.25 | 0 |
Monday, June 20, 2022 | 12 | 1 | 0 |
Monday, June 20, 2022 | 5 | 4 | 0 |
Monday, June 20, 2022 | 8 | 6 | 0 |
Monday, June 20, 2022 | 8 | 1 | 0 |
Monday, June 20, 2022 | 8 | 5 | 0 |
Tuesday, June 21, 2022 | 8 | 7.5 | 0 |
Tuesday, June 21, 2022 | 12 | 5 | 0 |
Tuesday, June 21, 2022 | 5 | 7 | 0 |
Tuesday, June 21, 2022 | 12 | 1 | 0 |
Tuesday, June 21, 2022 | 5 | 1 | 0 |
Tuesday, June 21, 2022 | 5 | 0.3 | 0 |
Tuesday, June 21, 2022 | 12 | 4 | 0 |
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))
@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.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
User | Count |
---|---|
27 | |
17 | |
16 | |
12 | |
11 |
User | Count |
---|---|
38 | |
29 | |
22 | |
20 | |
18 |