Forum Discussion
Jayadev
Helper I
8 years agoCalculating difference between dates comparing previous row
Hi I have a table containing patients admission and discharge details. The objective is to find out patients re-admitted after discharge. If re-admitted in less than 5 days it should be alerted....
- 8 years ago
Re Admission = VAR PreviousDischargeDate = CALCULATE ( MAX ( TableName[DISCHARGEDATE] ), FILTER ( ALLEXCEPT ( TableName, TableName[PatientID] ), TableName[Index] = EARLIER ( TableName[Index] ) - 1 ) ) RETURN IF ( NOT ( ISBLANK ( PreviousDischargeDate ) ), IF ( PreviousDischargeDate < TableName[AdmitDate], DATEDIFF ( PreviousDischargeDate, TableName[AdmitDate], DAY ) ) )Try this revised formula
- 8 years ago
Hi,
Super solution, thanks a lot, it works perfect.
Warmest regards Jay, Once again Thanks.
Jayadev
Helper I
8 years agoThanks a lot for your valuable inputs. I am getting the following error. Please help.
In DATEDIFF function, the start date cannot be greater than the end date
Regards,
Jay
Zubair_Muhammad
Community Champion
8 years agoRe Admission =
VAR PreviousDischargeDate =
CALCULATE (
MAX ( TableName[DISCHARGEDATE] ),
FILTER (
ALLEXCEPT ( TableName, TableName[PatientID] ),
TableName[Index]
= EARLIER ( TableName[Index] ) - 1
)
)
RETURN
IF (
NOT ( ISBLANK ( PreviousDischargeDate ) ),
IF (
PreviousDischargeDate < TableName[AdmitDate],
DATEDIFF ( PreviousDischargeDate, TableName[AdmitDate], DAY )
)
)
Try this revised formula
- Jayadev8 years ago
Helper I
Hi,
Super solution, thanks a lot, it works perfect.
Warmest regards Jay, Once again Thanks.