Forum Discussion

tameemyousaf's avatar
tameemyousaf
Helper I
5 years ago
Solved

Difference Between Two Dates in Single Column

Hi,

I have data that has timestamp in sigle row. I want to calculate the difference (in seconds or minuites) between two timestamps and need to show in another column or measure. Can anyone please help. Below is the screenshot of data.

 

 

  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi tameemyousaf ,

     

    Check the formula.

    Column = 
    var lasttime = CALCULATE(MAX('Table'[timestamp]),FILTER('Table','Table'[timestamp]<EARLIER('Table'[timestamp])))
    return
    IF(ISBLANK(lasttime),BLANK(),DATEDIFF(lasttime,'Table'[timestamp],MINUTE))

     

    Best Regards,

    Jay

7 Replies

      • Fowmy's avatar
        Fowmy
        Super User

        tameemyousaf 

        You can add the following New Column to your table to get the time difference in seconds.

        Difference = 
        var __datetime = Table20[Date] + Table20[Time]
        var __predatetime = 
            MAXX(
                FILTER(
                    ADDCOLUMNS(
                        Table20,
                        "@DateTime",
                            Table20[Date] + Table20[Time]
                    ),
                    [@DateTime] < __datetime
                ),
                [@DateTime]
            )
        return
        DATEDIFF( __predatetime,__datetime,SECOND )
        

         



  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi tameemyousaf ,

     

    Check the formula.

    Column = 
    var lasttime = CALCULATE(MAX('Table'[timestamp]),FILTER('Table','Table'[timestamp]<EARLIER('Table'[timestamp])))
    return
    IF(ISBLANK(lasttime),BLANK(),DATEDIFF(lasttime,'Table'[timestamp],MINUTE))

     

    Best Regards,

    Jay