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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
saur_dash
New Member

Calculate difference between two DateTime values in different rows

I'm so sorry if a similar question has been answered before, but I'm new to DAX and have been struggling to implement DAX measures I've found on this forum for calculating the difference between DateTime values in different rows.

 

I am working with a large dataset comprised of invoice numbers and payment statuses, and I need to dynamically calculate the time difference between two filtered statuses as follows:

 

Source:

Source.png

 

 

 

 

 

 

 

 

 

 

Desired Output:

Output.png

 

I would ideally like to be able to filter the Start and End Status in the output matrix with a Slicer, any help you could give me to solve this problem would be very much appreciated. Thank you for your time.

1 ACCEPTED SOLUTION
Phil_Seamark
Microsoft Employee
Microsoft Employee

Hi @saur_dash

 

You could try adding this calculated column to your table.

 

Duration = 

VAR MyLastDate = 
    MINX(
        FILTER(
            'Table1',
            'Table1'[Invoice Number] = EARLIER('Table1'[Invoice Number]) &&
            EARLIER('Table1'[Payment Status]) = "Captured" && 
            'Table1'[Payment Status] = "Authorised"
            ),
        'Table1'[Event Date])
        
RETURN IF(MyLastDate<>BLANK(),FORMAT('Table1'[Event Date]- MyLastDate,"HH:MM:SS") )

It will only show a value on rows with a status of "Captured", and the value will be the value in Hours, Mins and Seconds since the row from the same Invoice Number with a status of "Authorised"


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

6 REPLIES 6
Phil_Seamark
Microsoft Employee
Microsoft Employee

Hi @saur_dash

 

You could try adding this calculated column to your table.

 

Duration = 

VAR MyLastDate = 
    MINX(
        FILTER(
            'Table1',
            'Table1'[Invoice Number] = EARLIER('Table1'[Invoice Number]) &&
            EARLIER('Table1'[Payment Status]) = "Captured" && 
            'Table1'[Payment Status] = "Authorised"
            ),
        'Table1'[Event Date])
        
RETURN IF(MyLastDate<>BLANK(),FORMAT('Table1'[Event Date]- MyLastDate,"HH:MM:SS") )

It will only show a value on rows with a status of "Captured", and the value will be the value in Hours, Mins and Seconds since the row from the same Invoice Number with a status of "Authorised"


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Thanks for your help Phil.

 

I can't wait to try this!

 

 

This is what I get.  I substituted your lengthy invoice numbers for much simpler version for my testing.

 

Captured.png


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

That's amazing, thank you Phil! I am working on this now and seeing how you tackled the problem is an eye-opener.

Phil_Seamark
Microsoft Employee
Microsoft Employee

HI @saur_dash,

 

Your post was empty under Source: and Desired Output:, so can you reply and try again? 🙂


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Thanks for your reply Phil,

 

Sorry about the error, I've fixed the images. Any help you could give would be greatly appreciated.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

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

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.