Forum Discussion

pak's avatar
pak
Helper II
8 years ago
Solved

Time difference between next row

Hi all,

 

I have another question,

 

A want to to count time difference between actual row and next row, when "bit" equals 1, like beneath:

Date/TimeBitTime Difference
2018-01-11T17:03:00110
2018-01-11T17:03:10110
2018-01-11T17:03:2014
2018-01-11T17:03:24110
2018-01-11T17:03:34110
2018-01-11T17:03:44110
2018-01-11T17:03:5416
2018-01-11T17:04:000 
2018-01-11T17:04:100 
2018-01-11T17:04:160 

 

There is no function for next row in table. I've tried different functions but always with error or 0 value in TimeDifference.

I also added two index column. The difference between them is: Index.1=Index + 1. Tried to use it but i have syntax error:

 

I made this using method from this tutorial:

https://www.youtube.com/watch?v=xN2IRXQ2CvI&app=desktop

 

But maybe there is another, better way?

What will happen when i delete column used to merge tables, when my data is live streamed from IoT Hub to Azure StreamAnalytics to TableStorage, to Power BI. Would it work for another rows after?

 

  • pak

     

    May be a MEASURE instead of a column would handle memory better.

    Try this MEASURE

     

    Time Difference Measure =
    VAR NextRow =
        CALCULATE (
            MIN ( TableName[Date/Time] ),
            FILTER (
                ALL ( TableName ),
                TableName[Date/Time] > SELECTEDVALUE ( TableName[Date/Time] )
            )
        )
    RETURN
        IF (
            SELECTEDVALUE ( TableName[Bit] ) = 1,
            DATEDIFF ( SELECTEDVALUE ( TableName[Date/Time] ), NextRow, SECOND )
        )

14 Replies