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

DATEDIFF Between Two Columns for Same Value

Hi,

 

So I have a huge table with repeating patients for a hospital. I want to know when the DATEDIFF (in days) between the time they got discharged and the time they came back and readmitted. Not sure if you can see, but in the example (screenshot) below, this patient was first discharged on Sept 5th, 2018, but then came back on September 9th, 2018 (4 days difference). Then, they got discharged on September 10th, and then readmitted on September 30th (20 days difference). I want to know the interval in days between those two dates. Therefore, it has to be a DATEDIFF column or measure between two columns and different rows. Is this doable?

POWERBI.JPG

 

 

 

4 REPLIES 4
Zubair_Muhammad
Community Champion
Community Champion

@Anonymous

 

Try this as calculated column

 

Calc Column =
VAR PreviousRow =
    TOPN (
        1,
        FILTER (
            Table1,
            [Name] = EARLIER ( [Name] )
                && [Discharge Date] < EARLIER ( [Discharge Date] )
        ),
        [Discharge Date], DESC
    )
VAR PreviousDischargeDate =
    MAXX ( PreviousRow, [Discharge Date] )
RETURN
    DATEDIFF ( PreviousDischargeDate, [Admission date], DAY )

Regards
Zubair

Please try my custom visuals
Anonymous
Not applicable

@Zubair_Muhammad it kind of worked..but is it possible to have the first admission date as 0? I am not sure what value it is yielding since it is the first admission date and there are no prior discharge date. Powerbi2.JPG

@Anonymous

 

Sorry for late reply. I had to go out

 

When I use your sample data I get correct results....the first entry shows blank

See the pic below

 

patents.png


Regards
Zubair

Please try my custom visuals
Anonymous
Not applicable

@Zubair_Muhammad Not exactly sure why I have values. I will try to figure it out. Thanks for your help!

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.