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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Calculate Duration Column From Status's

Hello all,
I'm trying to figure out how to calculate the Duration of each status change from 'Old Value' to 'New Value' using the 'CreatedDate' column.

sirajerthat_0-1614627774943.png


For every 'Case #', everytime the 'New Value' column changes to the next iteration of 'Old Value', subtract the 'CreatedDate' with the earlier 'CreatedDate' (sorted by ascending) and output it in hh:mm:ss format in the 'Status Duration' column. My ultimate goal is to create visualizations of how long the total number of Cases and each iteration of a Case, were in-progress, waiting on customer, waiting on QA, etc..., How would I go about doing this? Thank you for the help! 

1 ACCEPTED SOLUTION

Hi, @Anonymous 

You can make some changes to the dax formulas.

 

Calculated column 1:

rank_table = RANKX(FILTER(ALL('Table'),'Table'[CaseId]=EARLIER('Table'[CaseId])),'Table'[CreatedDate],,ASC)

 

Calculated column 2:

Status Duration =

VAR res =

    MINX (

        FILTER (

            ALL ( 'Table' ),

            'Table'[rank_table]

                = EARLIER ( 'Table'[rank_table] ) + 1&&'Table'[CaseId]=EARLIER('Table'[CaseId])

        ),

        'Table'[CreatedDate]

    ) - 'Table'[CreatedDate]

RETURN

    IF ( 'Table'[NewValue] = "Closed", BLANK (), FORMAT ( res, "hh:mm:ss" ) )

 

 

Best Regards,

Caiyun Zheng

 

Is that the answer you're looking for? 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

5 REPLIES 5
v-cazheng-msft
Community Support
Community Support

Hi, @Anonymous 

You can create two Calculated columns to get the result you want.

 

Calculated column 1:

rank_table = RANKX('Table','Table'[CreatedDate],,ASC)

 

Calculated column 2:

Status Duration =

VAR res =

    MINX (

        FILTER (

            ALL ( 'Table' ),

            'Table'[rank_table]

                = EARLIER ( 'Table'[rank_table] ) + 1

        ),

        'Table'[CreatedDate]

    ) - 'Table'[CreatedDate]

RETURN

    IF ( 'Table'[NewValue] = "Closed", BLANK (), FORMAT ( res, "hh:mm:ss" ) )

 

The result looks like this:

v-cazheng-msft_0-1614854940644.png

 

Here is the pbix.

 

Best Regards,

Caiyun Zheng

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Anonymous
Not applicable

thank you for reply! unfortunately this won't work fro me because there's many Cases that may have been done sequentially. ranking only by createdDate won't work. I need to find a way to filter by createdDate  AND caseID, is there a way to do that?

Hi, @Anonymous 

You can make some changes to the dax formulas.

 

Calculated column 1:

rank_table = RANKX(FILTER(ALL('Table'),'Table'[CaseId]=EARLIER('Table'[CaseId])),'Table'[CreatedDate],,ASC)

 

Calculated column 2:

Status Duration =

VAR res =

    MINX (

        FILTER (

            ALL ( 'Table' ),

            'Table'[rank_table]

                = EARLIER ( 'Table'[rank_table] ) + 1&&'Table'[CaseId]=EARLIER('Table'[CaseId])

        ),

        'Table'[CreatedDate]

    ) - 'Table'[CreatedDate]

RETURN

    IF ( 'Table'[NewValue] = "Closed", BLANK (), FORMAT ( res, "hh:mm:ss" ) )

 

 

Best Regards,

Caiyun Zheng

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

amitchandak
Super User
Super User

@Anonymous , Try a new column like

 


new column =
var _oldvalue = [newvalue]
return
datediff(maxx(filter(Table, [CaseID] = earlier([Case ID]) && [newvalue] <> [oldvalue] && [newvalue] =_oldvalue && [CreatedDate] <earlier([CreatedDate])),[CreatedDate]),[CreatedDate],minute)

Anonymous
Not applicable

Thank you for the reply! Unfortunately this didn't work. After I isolated one case, and made the CreatedDate sorted as ascending, there is many blank spots under the new duration status column where I put your formula as you can see here: 
Case History Table Image  

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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