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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Anonymous
Not applicable

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
Anonymous
Not applicable

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
Community Champion
Community Champion

@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



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.