This is best Fabric, Power BI, SQL and AI community event. How do we know? The last event sold out! Save €200 with code FABCMTY200.
Register nowA new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.
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. I have calculated in excel manually, how to write DAX to achieve this result ? Just a comparison with previous row will not help, It should check the same paitent re-admission. In below example there is 1 patient re-admitted after 1 day.
Please help to find out a solution.
The sample data prepared in excel is given in the attached image.
Solved! Go to Solution.
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
Hi,
Super solution, thanks a lot, it works perfect.
Warmest regards Jay, Once again Thanks.
Hi @Jayadev
Try this solution
First add an Index Column for each PATIENTID. This will help in further calculations
Index =
RANKX (
FILTER ( TableName, [PatientID] = EARLIER ( [PatientID] ) ),
[AdmitDate],
,
ASC,
DENSE
)
Code beutified with Dax Formatter by SQLBINow you can get the Re-admission calculated column using this formula
Re Admission =
VAR PreviousDischargeDate =
CALCULATE (
MAX ( TableName[DISCHARGEDATE] ),
FILTER (
ALLEXCEPT ( TableName, TableName[PatientID] ),
TableName[Index]
= EARLIER ( TableName[Index] ) - 1
)
)
RETURN
IF (
NOT ( ISBLANK ( PreviousDischargeDate ) ),
DATEDIFF ( PreviousDischargeDate, TableName[AdmitDate], DAY )
)
Thanks 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
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
Hi,
Super solution, thanks a lot, it works perfect.
Warmest regards Jay, Once again Thanks.
Check out the May 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 32 | |
| 25 | |
| 23 | |
| 22 | |
| 13 |
| User | Count |
|---|---|
| 61 | |
| 47 | |
| 27 | |
| 24 | |
| 19 |