cancel
Showing results for
Did you mean:

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a \$100 discount. Register Now

Frequent Visitor

## 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
Community Support

Hi @Walter56 ,

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]
TIME ( 8, 0, 0 )
TIME ( 17, 0, 0 )
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 (
TIME ( HOUR ( StartDate ), MINUTE ( StartDate ), SECOND ( StartDate ) )
),
)
VAR EndHour =
IF (
WEEKDAY ( EndDate, 2 ) < 6,
MIN (
TIME ( HOUR ( EndDate ), MINUTE ( EndDate ), SECOND ( EndDate ) )
),
)
RETURN
IF (
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

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 REPLIES 2
Community Support

Hi @Walter56 ,

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]
TIME ( 8, 0, 0 )
TIME ( 17, 0, 0 )
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 (
TIME ( HOUR ( StartDate ), MINUTE ( StartDate ), SECOND ( StartDate ) )
),
)
VAR EndHour =
IF (
WEEKDAY ( EndDate, 2 ) < 6,
MIN (
TIME ( HOUR ( EndDate ), MINUTE ( EndDate ), SECOND ( EndDate ) )
),
)
RETURN
IF (
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

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Super User

@Walter56 See if this approach gets you there:

Hour Breakdown - Microsoft Fabric Community

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Announcements

#### Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

#### Power BI Monthly Update - February 2024

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

#### Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

#### Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors