Dimu Rasika
Dimu Rasika

Reputation: 11

How to calculate time difference in Power BI

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?

enter image description here

I'm new to this & want to know how to do it please

Upvotes: 1

Views: 2656

Answers (2)

danchdrezzing
danchdrezzing

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.

  1. You can to go into power query (transform data) and create an index column this will give each datetime as unique identifier. Unique Identifier

  2. Create a custom column using this code

    TimeDiff = if('Sheet1'[Index] <> 1, Sheet1[Timestamp] - LOOKUPVALUE ( Sheet1[Timestamp], Sheet1[Index], Sheet1[Index] - 1 ))

  3. In format, select h:nn:ss and this will display you differenceFinal

Upvotes: 0

horseyride
horseyride

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"

enter image description here

Upvotes: 3

Related Questions