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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register 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

2 ACCEPTED SOLUTIONS
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
)

View solution in original post

Anonymous
Not applicable

Hi @Taro_Gulat ,

 

I think you can also try measure to achieve your goal.

MEASURE =
VAR _VirtualTable =
    ADDCOLUMNS (
        FILTER ( 'Table', 'Table'[Item] = "B" && 'Table'[Type] = "X" ),
        "DateDiff",
            VAR _CurrentDateTime = [Date]
            VAR _MINDatetime =
                MINX (
                    FILTER (
                        ALL ( 'Table' ),
                        'Table'[Item] = "C"
                            && 'Table'[Type] = "X"
                            && 'Table'[Date] > _CurrentDateTime
                    ),
                    'Table'[Date]
                )
            RETURN
                DATEDIFF ( [Date], _MINDatetime, MINUTE )
    )
RETURN
    AVERAGEX ( _VirtualTable, [DateDiff] )

Result is as below.

vrzhoumsft_0-1736756731513.png

Best Regards,
Rico Zhou

 

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

Hi @Taro_Gulat ,

 

I think you can also try measure to achieve your goal.

MEASURE =
VAR _VirtualTable =
    ADDCOLUMNS (
        FILTER ( 'Table', 'Table'[Item] = "B" && 'Table'[Type] = "X" ),
        "DateDiff",
            VAR _CurrentDateTime = [Date]
            VAR _MINDatetime =
                MINX (
                    FILTER (
                        ALL ( 'Table' ),
                        'Table'[Item] = "C"
                            && 'Table'[Type] = "X"
                            && 'Table'[Date] > _CurrentDateTime
                    ),
                    'Table'[Date]
                )
            RETURN
                DATEDIFF ( [Date], _MINDatetime, MINUTE )
    )
RETURN
    AVERAGEX ( _VirtualTable, [DateDiff] )

Result is as below.

vrzhoumsft_0-1736756731513.png

Best Regards,
Rico Zhou

 

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

 

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.