Reputation: 11
I have a table with a column having timestamp as it's value. I need to add a new column & calculate the time difference between 2 rows. How to do this?
I'm new to this & want to know how to do it please
Upvotes: 1
Views: 2656
Reputation: 83
Since you are new to this, I will try to help you out as much as I can, feel free to ask any question.
You can to go into power query (transform data) and create an index column this will give each datetime as unique identifier.
Create a custom column using this code
TimeDiff = if('Sheet1'[Index] <> 1, Sheet1[Timestamp] - LOOKUPVALUE ( Sheet1[Timestamp], Sheet1[Index], Sheet1[Index] - 1 ))
In format, select h:nn:ss and this will display you difference
Upvotes: 0
Reputation: 21298
Bring your data into powerquery, like using data... from table/range
Add column, index column
Add column, custom column, formula
= try [Timestamp] - #"Added Index"{[Index]-1}[Timestamp] otherwise null
to be fancy manually edit code to end with null, type duration)
#"Added Index" = Table.AddIndexColumn(#"PriorStepNameHere", "Index", 0, 1, Int64.Type),
#"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each try [Timestamp] - #"Added Index"{[Index]-1}[Timestamp] otherwise null, type duration)
in #"Added Custom"
Upvotes: 3