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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Anonymous
Not applicable

How to find second difference between two dates in the same column

I'm trying to replicate in powerbi what I have in the excel screenshot. I want to find the time difference between two adjacent dates and output the time difference in seconds to the next column.

powerbiexcelexample.PNG

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

Hi @Anonymous ,

You could try to add an index column and use the function of DATEDIFF to calculate. I created a calculated column to implement it that you can have a try.

let
    Source = Excel.Workbook(File.Contents("C:\Users\xueding\Desktop\DateTime.xlsx"), null, true),
    Sheet2_Sheet = Source{[Item="Sheet2",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet2_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"DateTime", type datetime}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1)
in
    #"Added Index"
Column = var last = CALCULATE(MAX('Table'[DateTime]),FILTER('Table','Table'[Index] =EARLIER( 'Table'[Index]) -1))
return
DATEDIFF(last,MAX('Table'[DateTime]),SECOND)

2.PNG

Best Regards,

Xue Ding

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-xuding-msft
Community Support
Community Support

Hi @Anonymous ,

You could try to add an index column and use the function of DATEDIFF to calculate. I created a calculated column to implement it that you can have a try.

let
    Source = Excel.Workbook(File.Contents("C:\Users\xueding\Desktop\DateTime.xlsx"), null, true),
    Sheet2_Sheet = Source{[Item="Sheet2",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet2_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"DateTime", type datetime}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1)
in
    #"Added Index"
Column = var last = CALCULATE(MAX('Table'[DateTime]),FILTER('Table','Table'[Index] =EARLIER( 'Table'[Index]) -1))
return
DATEDIFF(last,MAX('Table'[DateTime]),SECOND)

2.PNG

Best Regards,

Xue Ding

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
kentyler
Solution Sage
Solution Sage

I think the standard advice for doing calculations involving adjacent cells is to do it in Excel....Excel is designed for it, Power BI is not. Then load your data into Power BI to use its features for analysis.





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

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.

Top Solution Authors