The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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
Solved! Go to Solution.
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
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
@Anonymous See if this approach gets you there:
Hour Breakdown - Microsoft Fabric Community
User | Count |
---|---|
20 | |
8 | |
7 | |
7 | |
6 |
User | Count |
---|---|
28 | |
13 | |
12 | |
9 | |
8 |