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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Power BI Calendar with Specific Days of Week and Hours to Count

Hello,

 

I am using PowerBI for an analysis and I am a bit stuck on how to do one specific calculation. I have the times that an shift of employees (for simplicity) started working and the time they stopped. In this example they can work for multiple days at a time. So one row will have the information about that shift as well as their start date/time (say 10/1/2023 at 11am) to their stop date/time (say 10/3/2023 at 12pm).

 

I need to do an analysis to count how many hours each shift worked that were specifically weekends (Saturdays and Sundays) from 8am-5pm. The purpose of this is to calculate the hours paid that could have been avoidable overtime if it was not a weekend. I know how to create a calendar and how to flag specific days as weekends, but not sure how to include the time element or how to do a count to see how many hours each employee shift worked that was avoidable overtime.

 

Could someone help to point me in the right direction or idea? Thanks

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

Base on your description, it seems that you want to get the hours which exclude the weekends. And the normal working time is from 8:00 AM to 5:00 PM. You can refer the following thread to get it:

Solved: Re: Calculating working hours between 2 dates disr... - Microsoft Fabric Community

Working Hours =
VAR StartDate = 'YourTable'[Start Date/Time]
VAR EndDate = 'YourTable'[End Date/Time]
VAR BusinessHoursStart =
    TIME ( 8, 0, 0 )
VAR BusinessHoursEnd =
    TIME ( 17, 0, 0 )
VAR BusinessDays =
    COUNTROWS (
        FILTER (
            'YourCalendarTable',
            'YourCalendarTable'[Date] >= StartDate
                && 'YourCalendarTable'[Date] <= EndDate
                && WEEKDAY ( 'YourCalendarTable'[Date], 2 ) < 6
                && NOT ( 'YourCalendarTable'[Date] IN VALUES ( 'YourHolidaysTable'[Date] ) )
        )
    )
VAR StartHour =
    IF (
        WEEKDAY ( StartDate, 2 ) < 6,
        MAX (
            BusinessHoursStart,
            TIME ( HOUR ( StartDate ), MINUTE ( StartDate ), SECOND ( StartDate ) )
        ),
        BusinessHoursStart
    )
VAR EndHour =
    IF (
        WEEKDAY ( EndDate, 2 ) < 6,
        MIN (
            BusinessHoursEnd,
            TIME ( HOUR ( EndDate ), MINUTE ( EndDate ), SECOND ( EndDate ) )
        ),
        BusinessHoursEnd
    )
RETURN
    IF (
        BusinessDays > 0,
        ( BusinessDays - 1 ) * ( BusinessHoursEnd - BusinessHoursStart ) + ( EndHour - StartHour ),
        0
    )

If the above one can't help you get the expected result, please provide some raw data in the table (exclude sensitive data) with Text format and your expected result with backend logic and special examples.  It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Anonymous ,

Base on your description, it seems that you want to get the hours which exclude the weekends. And the normal working time is from 8:00 AM to 5:00 PM. You can refer the following thread to get it:

Solved: Re: Calculating working hours between 2 dates disr... - Microsoft Fabric Community

Working Hours =
VAR StartDate = 'YourTable'[Start Date/Time]
VAR EndDate = 'YourTable'[End Date/Time]
VAR BusinessHoursStart =
    TIME ( 8, 0, 0 )
VAR BusinessHoursEnd =
    TIME ( 17, 0, 0 )
VAR BusinessDays =
    COUNTROWS (
        FILTER (
            'YourCalendarTable',
            'YourCalendarTable'[Date] >= StartDate
                && 'YourCalendarTable'[Date] <= EndDate
                && WEEKDAY ( 'YourCalendarTable'[Date], 2 ) < 6
                && NOT ( 'YourCalendarTable'[Date] IN VALUES ( 'YourHolidaysTable'[Date] ) )
        )
    )
VAR StartHour =
    IF (
        WEEKDAY ( StartDate, 2 ) < 6,
        MAX (
            BusinessHoursStart,
            TIME ( HOUR ( StartDate ), MINUTE ( StartDate ), SECOND ( StartDate ) )
        ),
        BusinessHoursStart
    )
VAR EndHour =
    IF (
        WEEKDAY ( EndDate, 2 ) < 6,
        MIN (
            BusinessHoursEnd,
            TIME ( HOUR ( EndDate ), MINUTE ( EndDate ), SECOND ( EndDate ) )
        ),
        BusinessHoursEnd
    )
RETURN
    IF (
        BusinessDays > 0,
        ( BusinessDays - 1 ) * ( BusinessHoursEnd - BusinessHoursStart ) + ( EndHour - StartHour ),
        0
    )

If the above one can't help you get the expected result, please provide some raw data in the table (exclude sensitive data) with Text format and your expected result with backend logic and special examples.  It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Greg_Deckler
Community Champion
Community Champion

@Anonymous See if this approach gets you there:

Hour Breakdown - Microsoft Fabric Community



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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