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

calculated columns: Lost_date and reactivated_date

Hi, I wish to get help on a problem that I am trying to solve. I have a list of patients and their visit dates to a clinic. I want to create a column two columns: 1) Lost_date 2) reactivated date Lost Date: A patient becomes lost/inactive if he has not visited the clinic for more than 18 months since his/her last visit Reactivated-date: if a patient comes back to the clinic after being inactive for more than 18 months, then the new visit date is considered as reactivated_date Eg: Pat_Id: Visit_Date 2 5/6/2016 2 7/6/2016 ----- the patient becomes inactive on 1/6/2018 (the patient has not visited for 18 months) 2 5/8/2018 ----- the patient become reactivated on 5/8/2018 Any help would be great
1 ACCEPTED SOLUTION

Hi @Anonymous,

 

I modify calculated column formulas based on your expected result and sample data, please try to use it if it works:

Lost Date =
VAR prevDate =
    CALCULATE (
        MAX ( Lost[Visit_Date] ),
        FILTER (
            ALL ( Lost ),
            [patid] = EARLIER ( [patid] )
                && [Visit_Date] < EARLIER ( Lost[Visit_Date] )
        )
    )
RETURN
    IF (
        DATEDIFF ( prevDate, [Visit_Date], MONTH ) >= 18,
        DATE ( YEAR ( prevDate ), MONTH ( prevDate ) + 18, DAY ( prevDate ) )
    )


Reactive Date =
VAR nextDate =
    CALCULATE (
        MIN ( Lost[Visit_Date] ),
        FILTER (
            ALL ( Lost ),
            [patid] = EARLIER ( Lost[patid] )
                && [Visit_Date] >= EARLIER ( [Lost Date] )
        )
    )
RETURN
    IF ( [Lost Date] <> BLANK () && nextDate <> BLANK (), nextDate )

4.png


Regards,
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

13 REPLIES 13

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.