The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
I have 2 tables linked by Emp ID No in a many to many cardinality. I want to be able to look at a specific pay period and see the hours a person worked based on the position, team, division, or branch they were assigned to at the time by comparing the start and End dates in ORG table to the LaborDetail Pay Period dates. I'm very new to anything more complex than point and click in Power BI.
LaborDetail
Direct vs Overhead | EMP ID No | Full Name | Rollup Hrs | Labor Hours | Work Date | Pay Period End Date |
Overhead | E1985 | Marty McFly | REG | 1 | 1/28/2025 | 2/8/2025 |
Direct | E1985 | Marty McFly | REG | 15 | 1/29/2025 | 2/8/2025 |
Direct | E1985 | Marty McFly | REG | 31 | 1/23/2025 | 1/25/2025 |
Overhead | E1985 | Marty McFly | REG | 2 | 1/23/2025 | 1/25/2025 |
Overhead | E1234 | MINNIE MOUSE | REG | 3 | 11/6/2024 | 11/16/2024 |
Direct | E1234 | MINNIE MOUSE | REG | 13 | 11/6/2024 | 11/16/2024 |
Direct | E1234 | MINNIE MOUSE | REG | 7 | 10/26/2023 | 11/4/2023 |
Overhead | E1234 | MINNIE MOUSE | REG | 1 | 10/26/2023 | 11/4/2023 |
Direct | E5678 | Bluey | REG | 28 | 11/14/2023 | 11/18/2023 |
Overhead | E5678 | Bluey | REG | 4 | 11/14/2023 | 11/18/2023 |
Direct | E5678 | Bluey | REG | 22.5 | 6/12/2024 | 6/15/2024 |
Overhead | E5678 | Bluey | REG | 1.5 | 6/12/2024 | 6/15/2024 |
Direct | E007 | Bond James | REG | 3.25 | 8/7/2024 | 8/10/2024 |
Overhead | E007 | Bond James | REG | 4 | 8/7/2024 | 8/10/2024 |
Direct | E007 | Bond James | REG | 21.25 | 1/24/2025 | 1/25/2025 |
Overhead | E007 | Bond James | REG | 7.25 | 1/24/2025 | 1/25/2025 |
ORG
EMP ID No | Person | Grade | Position | Div | Branch | Team | Start | End |
E1234 | Minnie Mouse | 12 | Specialist | Div A | Facility | FRR | 11/17/2024 | 9/30/2025 |
E5678 | Bluey | 13 | Lead | Div A | Med 1 | Reception | 5/5/2024 | 9/30/2025 |
E1224 | Christmas Eve | 09 | Specialist | Div A | Med 2 | OR | 11/17/2024 | 9/30/2025 |
E007 | Bond James | 12 | Specialist | Div B | Support | SPC | 10/20/2024 | 9/30/2025 |
E1122 | Elizabeth Doe | 13 | Specialist | Div B | Sales | OEA | 1/26/2025 | 9/30/2025 |
E1985 | Marty McFly | 09 | Nurse | Div C | Med 2 | OR | 5/7/2023 | 9/30/2025 |
E9999 | Joe Smo | 14 | Mgr | Div C | Operations | OTB | 12/31/2023 | 9/30/2025 |
E1122 | Elizabeth Doe | 12 | Specialist | Div B | Support | AE | 11/17/2024 | 1/25/2025 |
E1234 | Minnie Mouse | 11 | Specialist | Div A | Facility | FRR | 5/21/2023 | 11/16/2024 |
E1224 | Christmas Eve | 07 | Specialist | Div A | Med 2 | TRI | 5/5/2024 | 11/16/2024 |
E1122 | Elizabeth Doe | 09 | Specialist | Div B | Support | AE | 6/20/2021 | 11/16/2024 |
E3333 | Krispie Kreme | 13 | Lead | Div B | Support | AE | 5/9/2021 | 10/19/2024 |
E007 | Bond James | 11 | Specialist | Div B | Elect Tech | UMS | 5/7/2023 | 10/19/2024 |
E5678 | Bluey | 13 | Specialist | Div A | Med 1 | Clinic | 10/1/2019 | 5/4/2024 |
E1224 | Christmas Eve | 07 | Specialist | Div A | Tech Ops | NIT | 3/26/2023 | 5/4/2024 |
E9999 | Joe Smo | 14 | Mgr | Div A | Tech Ops | TOP | 3/26/2023 | 12/30/2023 |
E1234 | Minnie Mouse | 11 | Specialist | Div A | Maintenance and Services Support | DLA | 1/30/2022 | 5/20/2023 |
E007 | Bond James | 09 | Specialist | Div B | Environmental | ENT | 12/6/2021 | 5/6/2023 |
E1985 | Mary McFly | 07 | LPN | Div C | Med 1 | Clinic | 1/30/2022 | 5/6/2023 |
Solved! Go to Solution.
Hi @Ellen_horton14 ,
I think you can try code as below to create a measure.
Labor hour base on Period =
CALCULATE (
SUM ( LaborDetail[Labor Hours] ),
FILTER (
LaborDetail,
LaborDetail[EMP ID No] = MAX ( ORG[EMP ID No] )
&& AND (
LaborDetail[Pay Period End Date] >= MAX ( ORG[Start] ),
LaborDetail[Pay Period End Date] <= MAX ( ORG[End] )
)
)
)
Result is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Can you please try this measure:
Hours_Worked_By_Assignment =
VAR SelectedPayPeriod = MAX('LaborDetail'[Pay Period End Date]) -- Get the selected Pay Period
VAR EmpID = SELECTEDVALUE('LaborDetail'[EMP ID No]) -- Get the employee ID
VAR WorkDate = MAX('LaborDetail'[Work Date]) -- Get the Work Date
-- Find matching assignment from ORG table
VAR AssignedRole =
CALCULATE(
MAX('ORG'[Position]),
'ORG'[EMP ID No] = EmpID &&
WorkDate >= 'ORG'[Start] &&
WorkDate <= 'ORG'[End]
)
-- Calculate total hours worked for the matching period
VAR TotalHours =
CALCULATE(
SUM('LaborDetail'[Labor Hours]),
'ORG'[EMP ID No] = EmpID &&
WorkDate >= 'ORG'[Start] &&
WorkDate <= 'ORG'[End]
)
RETURN
IF(NOT(ISBLANK(AssignedRole)), TotalHours, BLANK()) -- Show hours only if assignment exists
Hi @Ellen_horton14 ,
I think you can try code as below to create a measure.
Labor hour base on Period =
CALCULATE (
SUM ( LaborDetail[Labor Hours] ),
FILTER (
LaborDetail,
LaborDetail[EMP ID No] = MAX ( ORG[EMP ID No] )
&& AND (
LaborDetail[Pay Period End Date] >= MAX ( ORG[Start] ),
LaborDetail[Pay Period End Date] <= MAX ( ORG[End] )
)
)
)
Result is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
User | Count |
---|---|
15 | |
12 | |
8 | |
7 | |
7 |
User | Count |
---|---|
24 | |
20 | |
12 | |
10 | |
7 |