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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors