cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...