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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors