Forum Discussion

seb_BMW's avatar
seb_BMW
New Member
9 years ago
Solved

compute time difference between two lines in table

I have the following table:   Nr      position       time 1            in              12:23:10 2            in              12:25:19 1            out            12:28:59 3            in       ...
  • Anonymous's avatar
    Anonymous
    9 years ago

    You're looking for the Pivot function.

     

    • Pivot on Position (Value is Time, and be sure not to aggregate)
    • Use M to subtract the resulting in/out column values
    • Convert datatype to the Duration type

    Screenshots:

     

    The line of M:

    #"Added Difference" = Table.AddColumn(#"Pivoted Column", "Diff", each [out] - [in]),
  • v-yulgu-msft's avatar
    9 years ago

    Hi seb_BMW,

     

    Alternatively, you can achieve this in DAX.

     

    Create a calculated table based on below formula.

    new table =
    SUMMARIZE (
        'time difference',
        'time difference'[Nr],
        "time diff", DATEDIFF (
            MIN ( 'time difference'[time] ),
            MAX ( 'time difference'[time] ),
            SECOND
        )
    )

    Add a calculated column in order to format the time difference.

    Column =
    IF (
        'new table'[time diff] = 0,
        BLANK (),
        INT ( 'new table'[time diff] / 3600 )
            & ":"
            & INT ( MOD ( 'new table'[time diff], 3600 ) / 60 )
            & ":"
            & MOD ( MOD ( 'new table'[time diff], 3600 )60 )
    )