Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Leslie1015
Frequent Visitor

Get the Time Difference

Hello everyone,

 

Can someone help me create a calculated column to get the ouput below?

IDDateIndexOutput
A8/3/2023 7:45:051 
A8/3/2023 7:45:1520:00:10
A8/3/2023 7:45:1730:00:02
B8/3/2023 7:45:211 
B8/3/2023 7:45:2720:00:06
A8/3/2023 7:45:2740:00:10
A8/3/2023 7:46:0150:00:34
A8/3/2023 7:46:1560:00:14
C8/3/2023 7:46:311 
C8/3/2023 7:46:5020:00:19
C8/3/2023 7:47:2030:00:30
B8/3/2023 7:47:4030:02:13

 

1 ACCEPTED SOLUTION
v-cgao-msft
Community Support
Community Support

Hi @Leslie1015 ,

Calculated column:

Output 2 = 
VAR CurrentID = TableName[ID]
VAR CurrentIndex = TableName[Index]
VAR CurrentDate = TableName[Date]
VAR PreviousRow = 
    CALCULATE (
        MAX ( TableName[Date] ),
        ALLEXCEPT ( TableName, TableName[ID] ),
        TableName[Index] = CurrentIndex - 1
    )
RETURN
IF (
    CurrentIndex > 1,
    CurrentDate - PreviousRow,
    BLANK ()
)

vcgaomsft_0-1692759624692.png

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

2 REPLIES 2
v-cgao-msft
Community Support
Community Support

Hi @Leslie1015 ,

Calculated column:

Output 2 = 
VAR CurrentID = TableName[ID]
VAR CurrentIndex = TableName[Index]
VAR CurrentDate = TableName[Date]
VAR PreviousRow = 
    CALCULATE (
        MAX ( TableName[Date] ),
        ALLEXCEPT ( TableName, TableName[ID] ),
        TableName[Index] = CurrentIndex - 1
    )
RETURN
IF (
    CurrentIndex > 1,
    CurrentDate - PreviousRow,
    BLANK ()
)

vcgaomsft_0-1692759624692.png

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Greg_Deckler
Super User
Super User

@Leslie1015 See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
  __Current - __Previous


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

Top Solution Authors
Top Kudoed Authors