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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
ROYMMM
Advocate II
Advocate II

Calculate elapsed time between two records based on values in different colums (in DAX)

Hi,

 

I have a table with records containing status changes of tickets. What I want to know is how long it took for a ticket to change from a "To Be Approved" status to another status. (which means that a ticket has been reviewed) In the example below the ticket IDs are in the 3rd column. So for example ticket A01 is submitted for review on Jan 1st at 12:00PM. The ticket is reviewed on January 4th at 3PM. As tickets sometimes get reviewed randomnly it can be that a ticket that comes in later will be reviewed earlier than another one. Like below, ticket B01. Important to note: tickets might also be submitted for review several times. (see below ticket A01) So I want to know how long each indiviual review took.

 

 example.png

 

How can I add a column with the elapsed time for the records where the "Old status" value is "To Be Approved"?

 

Thanks for your help.

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

Hi @ROYMMM ,

 

You could create a rank column at first, then use FIRSTNONBLANK() function to calculate the time.

rank =
RANKX (
    FILTER ( 'Table', 'Table'[TID] = EARLIER ( 'Table'[TID] ) ),
    'Table'[ID],
    ,
    ASC,
    DENSE
)
Time =
VAR a =
    CALCULATE (
        FIRSTNONBLANK ( 'Table'[Date], 1 ),
        FILTER (
            'Table',
            'Table'[rank]
                = EARLIER ( 'Table'[rank] ) - 1
                && 'Table'[TID] = EARLIER ( 'Table'[TID] )
        )
    )
RETURN
    IF ( 'Table'[Old] = "To Be approved", DATEDIFF ( a, 'Table'[Date], DAY ) )

Here is my test file for your reference.

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

1 REPLY 1
v-eachen-msft
Community Support
Community Support

Hi @ROYMMM ,

 

You could create a rank column at first, then use FIRSTNONBLANK() function to calculate the time.

rank =
RANKX (
    FILTER ( 'Table', 'Table'[TID] = EARLIER ( 'Table'[TID] ) ),
    'Table'[ID],
    ,
    ASC,
    DENSE
)
Time =
VAR a =
    CALCULATE (
        FIRSTNONBLANK ( 'Table'[Date], 1 ),
        FILTER (
            'Table',
            'Table'[rank]
                = EARLIER ( 'Table'[rank] ) - 1
                && 'Table'[TID] = EARLIER ( 'Table'[TID] )
        )
    )
RETURN
    IF ( 'Table'[Old] = "To Be approved", DATEDIFF ( a, 'Table'[Date], DAY ) )

Here is my test file for your reference.

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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