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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Qotsa
Helper V
Helper V

Time between shift finish time and next shift start time

Hi,

 

Trying to find the "Break Time" between the shift finish time & the next shift start time per employee.

Attached is an excample of the shifts worked by one employee in a typical day.

Sample File 

 

Qotsa_0-1638703248815.png

 

 

 

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1638736380478.png

 

CNENFRNL_1-1638736429820.png

 


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

6 REPLIES 6
Qotsa
Helper V
Helper V

@CNENFRNL I would like the results from your calculated column 'shifted' up a row.

Instead of the first row blank, the last should be blank.
I've been tinkering with your formula but havebeen unable to achieve this.

Qotsa_0-1639471991766.png

 

Time Between Calls =
VAR __prev =
MAXX (
TOPN (
1,
FILTER (
'powerbi114 view_finance',
'powerbi114 view_finance'[carer_id]
= EARLIER ( 'powerbi114 view_finance'[carer_id] )
&& 'powerbi114 view_finance'[Date] = EARLIER ( 'powerbi114 view_finance'[Date] )
&& 'powerbi114 view_finance'[Finish Time]
<= EARLIER ( 'powerbi114 view_finance'[Start Time] )
),
'powerbi114 view_finance'[Finish Time]
),
'powerbi114 view_finance'[Finish Time]
)
RETURN
IF ( NOT ISBLANK ( __prev ), 'powerbi114 view_finance'[Start Time] - __prev )



Qotsa
Helper V
Helper V

@CNENFRNL Thks for your help. I just needed to add an earlier date filter to your code to get it to do what I needed.

Thks again. Much appreciated.

Break =
var __prev =
MAXX(
TOPN(
1,
FILTER('powerbi114 view_finance',
'powerbi114 view_finance'[carer_id] = EARLIER('powerbi114 view_finance'[carer_id])
&& 'powerbi114 view_finance'[date] = EARLIER('powerbi114 view_finance'[date])
&& 'powerbi114 view_finance'[Sched_Finish] <= EARLIER('powerbi114 view_finance'[Sched_Start])
),
'powerbi114 view_finance'[Sched_Finish]
),
'powerbi114 view_finance'[Sched_Finish]
)
return
IF( NOT ISBLANK(__prev),'powerbi114 view_finance'[Sched_Start]- __prev)
CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1638736380478.png

 

CNENFRNL_1-1638736429820.png

 


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

@CNENFRNL That works well in sample file but i think having other days and employees throws it off.

For every day I need to show it for each employee. For their first & last shift that day it should return blank.

 

sample pbix file link 

 

 

Qotsa_0-1638816011268.png

 

 

 

HotChilli
Super User
Super User

This will give you a column with the previous end time so you can get the difference with a subtraction:

Add a custom column (sub in previous step for #"Changed Type")

let a = [Sched_Start] in  List.Max(List.Select(#"Changed Type"[Sched_Finish], each _ <= a))

it will be a little more complex with different employee ids

 

@HotChilli TY. I need to have this in DAX rather than Query Editor.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.