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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

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 )
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

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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