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

Help with tracking the duration of multiple status changes

I have a data base that contains a number of assets and status changes, here is the data.

 

assetUUIDStatustimeHappenedUTC
d150Take Action6/3/2021 1:36
d151Take Action6/3/2021 1:36
d152Take Action6/3/2021 1:38
d150Take Action6/3/2021 1:43
d151SOS6/30/2021 22:50
d151SOS Cancel6/30/2021 22:50
d150SOS8/26/2021 3:18
d150Take Action8/26/2021 3:24
d150SOS Cancel8/26/2021 3:28

 

my first target was to create a duration formula between "SOS" and "SOS Cancel", this I have done.

 

My second request was to track the duration between  "SOS" and  "Take Action" status but there are more "Take Action" Status than  the "SOS" Status.

 

Is it possible to calculate a duration between "SOS" and "Take Action", only if it falls between "SOS" and "SOS Cancel" ?

I have no clue where to even begin to build something like this, 

 

I was also thinking there are other status changes that are different than "Take Action", is it possible to build something that would calculate a duration by using "Take Action" status then any status that happens before the "Take Action"?

 

I'm just begenning to get my head around DAX and starting to get some good results but this has me completly stumped.

 

2 REPLIES 2
pgiorgi1
Frequent Visitor

O.K. thank you for the forumula it makes allot of sense, now I've tried it however my results are showing up with all no results  the durations are coming up with zero as the results, I tried to change the duration to seconds from minutes and there are no duration numbers associated to it.   I'll keep working on it.

ERD
Super User
Super User

Hi @pgiorgi1 ,

You can try the measures below for 2 cases you've described:

1. calculate a duration between "SOS" and "Take Action", only if it falls between "SOS" and "SOS Cancel"

2. calculate a duration by using "Take Action" status then any (other) status that happens before the "Take Action"

duration#1 = 
VAR c_asset = SELECTEDVALUE ( T[assetUUID] )
VAR c_status = SELECTEDVALUE ( T[Status] )
VAR c_time = SELECTEDVALUE ( T[timeHappenedUTC] )
VAR prev_time =
    CALCULATE (
        MAX ( T[timeHappenedUTC] ),
        FILTER (
            ALLSELECTED ( T ),
            T[timeHappenedUTC] < c_time && T[assetUUID] = c_asset
        )
    )
VAR prev_status =
    CALCULATE (
        MAX ( T[Status] ),
        TOPN (
            1,
            FILTER (
                ALLSELECTED ( T ),
                T[timeHappenedUTC] < c_time && T[assetUUID] = c_asset
            ),
            T[timeHappenedUTC]
        )
    )
VAR next_status =
    CALCULATE (
        MAX ( T[Status] ),
        TOPN (
            1,
            FILTER (
                ALLSELECTED ( T ),
                T[timeHappenedUTC] > c_time && T[assetUUID] = c_asset
            ),
            T[timeHappenedUTC]
        )
    )
RETURN
    IF (
        c_status = "Take action" && prev_status = "SOS" && next_status = "SOS Cancel",
        DATEDIFF ( prev_time, c_time, MINUTE ),
        0
    )
duration#2 = 
VAR c_asset = SELECTEDVALUE ( T[assetUUID] )
VAR c_status = SELECTEDVALUE ( T[Status] )
VAR c_time = SELECTEDVALUE ( T[timeHappenedUTC] )
VAR prev_time =
    CALCULATE (
        MAX ( T[timeHappenedUTC] ),
        FILTER (
            ALLSELECTED ( T ),
            T[timeHappenedUTC] < c_time && T[assetUUID] = c_asset
        )
    )
VAR prev_status =
    CALCULATE (
        MAX ( T[Status] ),
        TOPN (
            1,
            FILTER (
                ALLSELECTED ( T ),
                T[timeHappenedUTC] < c_time && T[assetUUID] = c_asset
            ),
            T[timeHappenedUTC]
        )
    )
RETURN
    IF (
        c_status = "Take action" && prev_status <> "Take action",
        DATEDIFF ( prev_time, c_time, MINUTE ),
        0
    )

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

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

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.

Top Solution Authors