Reply
Jon_S
Frequent Visitor
Partially syndicated - Outbound

Working Hours based on hire / term dates

I'm trying to create a measure to show 8 hours per day (Mon-Fri only), per employee, only if the date is a date the employee was active, based on hire and termination dates.  It seems basic but struggling with this.

 

Below represents 8 hours per day, not considering hire or term dates.  This was calculated using:

Working Hours = sum('Calendar'[Working Hours])*count(Employees[Employee #])

 

Jon_S_0-1709051671576.png

 

I'm working with a simple mock data set - a basic employee table and basic calendar table.

Jon_S_1-1709051811215.png

Jon_S_2-1709051895791.png

 

I do not currently have any relationships between the calendar and employee table.

 

Jon_S_3-1709051953954.png

 

 

If I use employee 3, as an example, they should only show 8 hours per day on or after 4/15/2023 and on or before 9/30/2023.

 

What relationship is neccesary to make this work, and what would the measure look like?

1 ACCEPTED SOLUTION
Jon_S
Frequent Visitor

Syndicated - Outbound

I got it working using:

= 
 sumx(
    Employees,
    calculate(
        sum('Calendar'[Working Hours]),
        FILTER(
            'Calendar',
            'Calendar'[Date]>=Employees[Hire Date]&&
        'Calendar'[Date] <= if(ISBLANK(Employees[Term Date]),date(9999,12,31),Employees[Term Date]))))

 

Jon_S_0-1709214794463.png

 

 

View solution in original post

3 REPLIES 3
v-heq-msft
Community Support
Community Support

Syndicated - Outbound

Hi @Jon_S ,

Here some steps that I want to share, you can check them if they suitable for your requirement.

Here is my test data:

vheqmsft_0-1709099898062.pngvheqmsft_1-1709099910248.png

Create a measure

 

Active Working Hours = 
CALCULATE(
    SUM('Calendar'[Working Hours]),
    FILTER(
        'Calendar',
        'Calendar'[Date] >= SELECTEDVALUE(Employees[Hire Date]) && 'Calendar'[Date] <= 
        CALCULATE(
            IF(
                SELECTEDVALUE(Employees[Term Date]) = BLANK(),
                DATE(9999,12,31),
                SELECTEDVALUE(Employees[Term Date])
            )
    )
))

 

 

Final output

vheqmsft_2-1709100072559.png

Best regards,

Albert He

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Syndicated - Outbound

This gets really close and captures the correct values at the individual person level.  However, the total is not aggregating correctly (see image below).  For example, I would expect the Q1-2023 total to be 3,120.

 

Jon_S_0-1709132823776.png

 

Jon_S
Frequent Visitor

Syndicated - Outbound

I got it working using:

= 
 sumx(
    Employees,
    calculate(
        sum('Calendar'[Working Hours]),
        FILTER(
            'Calendar',
            'Calendar'[Date]>=Employees[Hire Date]&&
        'Calendar'[Date] <= if(ISBLANK(Employees[Term Date]),date(9999,12,31),Employees[Term Date]))))

 

Jon_S_0-1709214794463.png

 

 

avatar user

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)