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
madbaird
Frequent Visitor

Getting time between two dates in same column based on event criteria

I am trying to figure out how to get the difference between two dates based on the event.
I have event IDs as follows:

1=Created

2=Activated

3=Respond

4=Resolve

5=Closed

I need to get the days between created (ID1) to either the resolve time (ID4) or if not resolved, the days open as of today's date.
Sample from Current Table:

item_id Event_ID Event_Name date_hour_local
368901 1 Created 1/5/2024
368901 2 Activated 1/9/2024
368901 3Responded1/9/2024
368901 4Resolved1/9/2024
3689021Created1/5/2024
3689022Activated1/9/2024
3689023Responded1/9/2024
3689024Resolved1/9/2024
3689031Created1/5/2024
3689032Activated1/9/2024
3689033Responded1/9/2024
3689091Created1/3/2024
3689092Activated1/9/2024
3689093Responded1/9/2024
3689101Created1/9/2024
3689102Activated1/9/2024
3689103Responded1/9/2024
3689104Resolved1/9/2024
3689111Created1/9/2024
3689112Activated1/9/2024
3689113Responded1/9/2024
3689121Created1/9/2024
3689122Activated1/9/2024
3689123Responded1/9/2024
3689131Created1/9/2024
3689132Activated1/9/2024
3689133Responded1/9/2024
3689134Resolved1/9/2024

 

This DAX gets me close, but I just need the actual days open, so that I can use it in other parts of the design (ie Avg Days Open).

Days_Open =
VAR temp =
    TOPN(
        5,
        Filter(Ticket_Sum,
        Ticket_Sum[item_id]=EARLIER(Ticket_Sum[item_id])&&
        Ticket_Sum[date_hour_local]<EARLIER(Ticket_Sum[date_hour_local])
        ),
        [date_hour_local], desc
    )
  Return
   DATEDIFF(MINX(temp, Ticket_Sum[date_hour_local]), Ticket_Sum[date_hour_local], DAY)
1 ACCEPTED SOLUTION
Anonymous
Not applicable

HI @madbaird,

You can try to use the following measure formasi lot get the difference between two event names if helps:

formula = 
VAR created =
    CALCULATE (
        MIN ( 'Table'[date_hour_local] ),
        FILTER ( ALLSELECTED ( 'Table' ), [Event_Name] = "Created" ),
        VALUES ( 'Table'[item_id] )
    )
VAR resolved =
    CALCULATE (
        MAX ( 'Table'[date_hour_local] ),
        FILTER ( ALLSELECTED ( 'Table' ), [Event_Name] = "Resolved" ),
        VALUES ( 'Table'[item_id] )
    )
VAR lastest =
    CALCULATE (
        MAX ( 'Table'[date_hour_local] ),
        ALLSELECTED ( 'Table' ),
        VALUES ( 'Table'[item_id] )
    )
VAR eventList =
    CALCULATETABLE (
        VALUES ( 'Table'[Event_Name] ),
        ALLSELECTED ( 'Table' ),
        VALUES ( 'Table'[item_id] )
    )
RETURN
    IF (
        "Resolved" IN eventList,
        DATEDIFF ( created, resolved, DAY ),
        DATEDIFF ( created, lastest, DAY )
    )

Regards,

Xiaoxin Sheng

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

HI @madbaird,

You can try to use the following measure formasi lot get the difference between two event names if helps:

formula = 
VAR created =
    CALCULATE (
        MIN ( 'Table'[date_hour_local] ),
        FILTER ( ALLSELECTED ( 'Table' ), [Event_Name] = "Created" ),
        VALUES ( 'Table'[item_id] )
    )
VAR resolved =
    CALCULATE (
        MAX ( 'Table'[date_hour_local] ),
        FILTER ( ALLSELECTED ( 'Table' ), [Event_Name] = "Resolved" ),
        VALUES ( 'Table'[item_id] )
    )
VAR lastest =
    CALCULATE (
        MAX ( 'Table'[date_hour_local] ),
        ALLSELECTED ( 'Table' ),
        VALUES ( 'Table'[item_id] )
    )
VAR eventList =
    CALCULATETABLE (
        VALUES ( 'Table'[Event_Name] ),
        ALLSELECTED ( 'Table' ),
        VALUES ( 'Table'[item_id] )
    )
RETURN
    IF (
        "Resolved" IN eventList,
        DATEDIFF ( created, resolved, DAY ),
        DATEDIFF ( created, lastest, DAY )
    )

Regards,

Xiaoxin Sheng

Thank you, that seems to work as needed.

amitchandak
Super User
Super User

@madbaird , Try new column or measure

 

New column =
datediff([date_hour_local],coalease( maxx(filter(Table,[item_id] = earlier([item_id]) && [Event_ID] = earlier([Event_ID])-1), [date_hour_local]),[date_hour_local]), DAY)


New Measure =
AverageX( Table, if([Event_ID] >1, datediff([date_hour_local],coalease( maxx(filter(Table,[item_id] = earlier([item_id]) && [Event_ID] = earlier([Event_ID])-1), [date_hour_local]),[date_hour_local]), DAY)))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.