cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
timcorke
Helper I
Helper I

Date differences between dates with different status

Good afternoon, I'm hoping you could help me.

For each individual [UID] there are different status changes [ACTIVITY_TYPE] made up of REQUESTED, RESPONDED, CLOSED, CANCELLED based on the progress of communication.

Each time the status changes a new row is created, timestamped marked with an [ACTIVITY_ID] and the [ACTIVITY_TYPE] changes accordingly. 
The status changes can go back and forth between REQUESTED and RESPONDED but there is only one CLOSED and/or CANCELLED.
The date change is marked in the same date field ACTIVITY DATE.

 

UID ACTIVITY_DATE ACTIVITY_TYPE
12345 01/01/2022 REQUESTED
12345 10/01/2022 REQUESTED
12345 11/01/2022 RESPONDED
12345 13/01/2022 REQUESTED
12345 22/01/2022 RESPONDED
12345 23/01/2022 CLOSED

 

 

I'm looking to get the time between the first REQUESTED, and the first RESPONDED, even though future status changes could follow.

Any pointers would be welcomed,

Tim

 

 

 

 

 

 

2 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Picture1.png

 

Expected result: =
VAR firstrequesteddate =
    MINX (
        FILTER (
            Data,
            Data[UID] = MAX ( Data[UID] )
                && Data[ACTIVITY_TYPE] = "REQUESTED"
        ),
        Data[ACTIVITY_DATE]
    )
VAR firstrespondeddate =
    MINX (
        FILTER (
            Data,
            Data[UID] = MAX ( Data[UID] )
                && Data[ACTIVITY_TYPE] = "RESPONDED"
        ),
        Data[ACTIVITY_DATE]
    )
RETURN
    VALUE ( firstrespondeddate - firstrequesteddate )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

BarnabasToth
Resolver I
Resolver I

If you mean to create a calculated column, here is a similar apporach:

DaysToFirstResponse = 
VAR FirstRequestDate = 
    CALCULATE (
        MIN ( 'Table'[ACTIVITY_DATE] ),
        ALLEXCEPT ( 'Table', 'Table'[UID] ),
        'Table'[ACTIVITY_TYPE] = "REQUESTED"
    )
VAR FirstResponseDate = 
    CALCULATE (
        MIN ( 'Table'[ACTIVITY_DATE] ),
        ALLEXCEPT ( 'Table', 'Table'[UID] ),
        'Table'[ACTIVITY_TYPE] = "RESPONDED"
    )
RETURN
    DATEDIFF ( FirstRequestDate, FirstResponseDate, DAY )

 
Sample file available here.
Please mark this as a solution if it resolved your issue.

Regards

View solution in original post

5 REPLIES 5
timcorke
Helper I
Helper I

My apologies for the delay in acknowledging and best wishes to both @BarnabasToth and @Jihwan_Kim for their generosity responding. 

BarnabasToth
Resolver I
Resolver I

If you mean to create a calculated column, here is a similar apporach:

DaysToFirstResponse = 
VAR FirstRequestDate = 
    CALCULATE (
        MIN ( 'Table'[ACTIVITY_DATE] ),
        ALLEXCEPT ( 'Table', 'Table'[UID] ),
        'Table'[ACTIVITY_TYPE] = "REQUESTED"
    )
VAR FirstResponseDate = 
    CALCULATE (
        MIN ( 'Table'[ACTIVITY_DATE] ),
        ALLEXCEPT ( 'Table', 'Table'[UID] ),
        'Table'[ACTIVITY_TYPE] = "RESPONDED"
    )
RETURN
    DATEDIFF ( FirstRequestDate, FirstResponseDate, DAY )

 
Sample file available here.
Please mark this as a solution if it resolved your issue.

Regards

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Picture1.png

 

Expected result: =
VAR firstrequesteddate =
    MINX (
        FILTER (
            Data,
            Data[UID] = MAX ( Data[UID] )
                && Data[ACTIVITY_TYPE] = "REQUESTED"
        ),
        Data[ACTIVITY_DATE]
    )
VAR firstrespondeddate =
    MINX (
        FILTER (
            Data,
            Data[UID] = MAX ( Data[UID] )
                && Data[ACTIVITY_TYPE] = "RESPONDED"
        ),
        Data[ACTIVITY_DATE]
    )
RETURN
    VALUE ( firstrespondeddate - firstrequesteddate )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Many thanks for your time responding, this is really helpful thank you.


My only additional query is if there is no REQUESTED or RESPONDED. Looking deeper n the data identifies that many records, likely historical, have just CLOSED or CANCELLED so return 44124 or similar negative value as there are no dates to use. 

For me it returns BLANK ( ) when REQUESTED or RESPONDED is missing.

image.png

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors