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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Karolina_95
Frequent Visitor

Idle time calculation to show in a d:h:m: format and be sumable

Hi, I need to calculate the idle time between two colums (Next Arrival and previous departure). The calculation is working so that's great but the difference is shown in minutes as when counted in hours it's rounding up and not showing the precise difference.

I want to have that difference displayed in a day:hour:minute format and also be able to sum it up so I can use it for calculations.

Unfortunately I can't use the measure as the idle time calculation doesn't show there nor I can't calculate the idle time as a measure.

Arrival Time               Depart Time

29/12/2022 12.5229/12/2022 21.40
02/01/2023 08.1002/01/2023 13.20
03/01/2023 13.3003/01/2023 23.10
04/01/2023 00.1504/01/2023 10.10
04/01/2023 12.0704/01/2023 20.00
04/01/2023 21.4505/01/2023 02.00
05/01/2023 02.4005/01/2023 09.10
05/01/2023 11.2705/01/2023 17.50
05/01/2023 19.4506/01/2023 01.00
06/01/2023 03.0006/01/2023 09.00
06/01/2023 10.5506/01/2023 15.59
06/01/2023 18.5507/01/2023 03.00
07/01/2023 08.0007/01/2023 17.15

 

The idle time calculation is 

Idle time2 = VAR prevEnd =
CALCULATE (
MAX ( Table13[Depart Time]),
FILTER (
ALL ( Table13 ), [Arrival Time] < EARLIER ( Table13[Arrival Time] )
)
)
RETURN
DATEDIFF (Table13[Arrival Time], prevEnd, MINUTE) *-1
 
Is there any way to have it working?
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Karolina_95 ,

Please try below steps:

1. below is my test table
Table:

vbinbinyumsft_0-1676871749784.png

2. create a measure with below dax formula

Day Hour Minute =
VAR cur_dt =
    SELECTEDVALUE ( 'Table'[Depart Time] )
VAR cur_at =
    SELECTEDVALUE ( 'Table'[Arrival Time] )
VAR pre_dt =
    CALCULATE (
        MAX ( [Depart Time] ),
        FILTER ( ALL ( 'Table' ), [Arrival Time] < cur_at )
    )
VAR _val =
    DATEDIFF ( pre_dt, cur_at, MINUTE )
VAR _val1 =
    FORMAT ( _val / 1440, "0.00" )
VAR _val2 =
    IF ( ISBLANK ( _val1 ), BLANK (), FIND ( ".", _val1 ) - 1 )
VAR _val3 =
    FORMAT ( MOD ( _val, 1440 ) / 60, "0.00" )
VAR _val4 =
    IF ( ISBLANK ( _val3 ), BLANK (), FIND ( ".", FORMAT ( _val3, "0.00" ) ) - 1 )
VAR _a =
    IF ( ISBLANK ( _val ), BLANK (), MID ( _val1, 1, _val2 ) )
VAR _b =
    IF ( ISBLANK ( _val ), BLANK (), MID ( _val3, 1, _val4 ) )
VAR _c =
    IF ( ISBLANK ( _val ), BLANK (), MOD ( MOD ( _val, 1440 ), 60 ) )
RETURN
    IF ( ISBLANK ( _val ), BLANK (), _a & ":" & _b & ":" & _c )

3. add  a table visual with table fields and measure

vbinbinyumsft_1-1676871831550.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
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
Karolina_95
Frequent Visitor

Hi @Anonymous thanks for the solution!

I think that should work however for some reason when adding it into the report I got an error message with Find function. Do you have any ideas why that is happening? The code doesn't show any errors after I copied and adjusted it to my data.

Karolina_95_1-1676900798073.png

 

 

Anonymous
Not applicable

Hi @Karolina_95 ,

Please try below steps:

1. below is my test table
Table:

vbinbinyumsft_0-1676871749784.png

2. create a measure with below dax formula

Day Hour Minute =
VAR cur_dt =
    SELECTEDVALUE ( 'Table'[Depart Time] )
VAR cur_at =
    SELECTEDVALUE ( 'Table'[Arrival Time] )
VAR pre_dt =
    CALCULATE (
        MAX ( [Depart Time] ),
        FILTER ( ALL ( 'Table' ), [Arrival Time] < cur_at )
    )
VAR _val =
    DATEDIFF ( pre_dt, cur_at, MINUTE )
VAR _val1 =
    FORMAT ( _val / 1440, "0.00" )
VAR _val2 =
    IF ( ISBLANK ( _val1 ), BLANK (), FIND ( ".", _val1 ) - 1 )
VAR _val3 =
    FORMAT ( MOD ( _val, 1440 ) / 60, "0.00" )
VAR _val4 =
    IF ( ISBLANK ( _val3 ), BLANK (), FIND ( ".", FORMAT ( _val3, "0.00" ) ) - 1 )
VAR _a =
    IF ( ISBLANK ( _val ), BLANK (), MID ( _val1, 1, _val2 ) )
VAR _b =
    IF ( ISBLANK ( _val ), BLANK (), MID ( _val3, 1, _val4 ) )
VAR _c =
    IF ( ISBLANK ( _val ), BLANK (), MOD ( MOD ( _val, 1440 ), 60 ) )
RETURN
    IF ( ISBLANK ( _val ), BLANK (), _a & ":" & _b & ":" & _c )

3. add  a table visual with table fields and measure

vbinbinyumsft_1-1676871831550.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.