Forum Discussion
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?
4 Replies
- Zubair_MuhammadCommunity 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 )- AnonymousNot 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.
- Zubair_MuhammadCommunity Champion
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