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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Taro_Gulat
Regular Visitor

Dynamic Timestamp Difference

Hi all, 

 

I am having some difficulty in Dax with the below scenario:

 

Taro_Gulat_0-1736489896008.png

I need to calculate the difference in datetime between item = B, Type = X and item = C, Type = first available X. Example: Difference between row number 2 and 4, result is 1 minute then difference between row number 7 and 9, result is 1 minute and difference between row number 12 and 14, result is 1 minute. Once all differences are calculated an average will be required based on based on number of results.

 

I tried with calculated columns but not giving me desired results. 

 

Can anyone help?

Thanks

1 REPLY 1
johnt75
Super User
Super User

You could create a calculated column like

Time difference =
IF (
    'Table'[Item] = "B"
        && 'Table'[Type] = "X",
    VAR CurrentTime = 'Table'[Time]
    VAR NextAvailableTime =
        MINX (
            FILTER (
                ALL ( 'Table'[Item], 'Table'[Type], 'Table'[Time] ),
                'Table'[Item] = "C"
                    && 'Table'[Type] = "X"
                    && 'Table'[Time] > CurrentTime
            ),
            'Table'[Time]
        )
    VAR Result =
        DATEDIFF ( CurrentTime, NextAvailableTime, MINUTE )
    RETURN
        Result
)

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.