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

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

Reply
orobbsh
New Member

Difference between 2 times

HI 

i want to find the difference between 2 time in separate rows like this table

 

 image.png

 

 

i want the result to be like this : 

orobbsh_0-1669815550913.png

 

1 ACCEPTED SOLUTION
v-yinliw-msft
Community Support
Community Support

Hi @orobbsh , 

 

You can try this method:

Create two columns:

var =
CALCULATE (
MAX ( 'Table'[end] ),
FILTER ( 'Table', 'Table'[surgery id] = EARLIER ( 'Table'[surgery id] ) - 1 ))
 
difference = MINUTE('Table'[start] - 'Table'[var])
 
New tables:
Result =
TOPN (
4,
SELECTCOLUMNS (
'Table',
"Surgery",
IF (
'Table'[surgery id] <= 3,
"S" & 'Table'[surgery id],
IF ( 'Table'[surgery id] = 5, "S4" )
),
"start time", 'Table'[start],
"end time",
IF (
'Table'[surgery id] < 3,
[end],
IF (
'Table'[surgery id] = 3
|| 'Table'[surgery id] = 4,
CALCULATE (
MAX ( 'Table'[end] ),
FILTER ( 'Table', 'Table'[surgery id] = 3 || 'Table'[surgery id] = 4 )
),
TIME ( 12, 0, 0 )
)
),
"time difference", 'Table'[difference]
),
[Surgery], DESC
)
 
The result is:
vyinliwmsft_0-1669872827490.png

 


 

 

Hope this helps you.

Here is my PBIX file.

 

Best Regards,

Community Support Team _Yinliw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-yinliw-msft
Community Support
Community Support

Hi @orobbsh , 

 

You can try this method:

Create two columns:

var =
CALCULATE (
MAX ( 'Table'[end] ),
FILTER ( 'Table', 'Table'[surgery id] = EARLIER ( 'Table'[surgery id] ) - 1 ))
 
difference = MINUTE('Table'[start] - 'Table'[var])
 
New tables:
Result =
TOPN (
4,
SELECTCOLUMNS (
'Table',
"Surgery",
IF (
'Table'[surgery id] <= 3,
"S" & 'Table'[surgery id],
IF ( 'Table'[surgery id] = 5, "S4" )
),
"start time", 'Table'[start],
"end time",
IF (
'Table'[surgery id] < 3,
[end],
IF (
'Table'[surgery id] = 3
|| 'Table'[surgery id] = 4,
CALCULATE (
MAX ( 'Table'[end] ),
FILTER ( 'Table', 'Table'[surgery id] = 3 || 'Table'[surgery id] = 4 )
),
TIME ( 12, 0, 0 )
)
),
"time difference", 'Table'[difference]
),
[Surgery], DESC
)
 
The result is:
vyinliwmsft_0-1669872827490.png

 


 

 

Hope this helps you.

Here is my PBIX file.

 

Best Regards,

Community Support Team _Yinliw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

philouduv
Resolver III
Resolver III

Hello @orobbsh ,
I do not know if it feasible in your situation but if you delete the first cell of start (8:00 AM) and that you shift all cells in the start column 1 cell up, you would only need to create a new column calculating the difference between start and end to have the time difference without jugling with different lines.

Best regards

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.