Question

I have been stumped on this particular task for weeks. Any help would be greatly appreciated.

I have three columns I am working with: Date Admitted to Hospital (date column), Date Discharged (date column), and Hospital Duration (calculated column)

Hospital Duration currently looks like this:

=IF(ISBLANK([Date Discharged]),DATEDIF([Date Admitted to Hospital],TODAY(),"d"))

This is great because it accounts for a scenario where 'Date Admitted to Hospital' is filled in, but 'Date Discharged' is blank. However, it does not account for when neither of the columns are filled out - and when BOTH of the columns are filled out, the result I get in 'Hospital Duration' is "no"??

Was it helpful?

Solution

Based on your requirements..I'm posting the below.

=IF(AND(NOT(ISBLANK(AdmitDate)),NOT(ISBLANK(DischargeDate))),DATEDIF(AdmitDate,DischargeDate,"d"),IF(AND(NOT(ISBLANK(AdmitDate)),ISBLANK(DischargeDate)),DATEDIF(AdmitDate,TODAY(),"d"),""))

enter image description here

Updating the formula to adjust the new requirements


If both AdmitDate and DischargeDate are blank, is there a way to show the HospitalStay column as 0

=IF(AND(NOT(ISBLANK(AdmitDate)),NOT(ISBLANK(DischargeDate))),DATEDIF(AdmitDate,DischargeDate,"d"),IF(AND(NOT(ISBLANK(AdmitDate)),ISBLANK(DischargeDate)),DATEDIF(AdmitDate,TODAY(),"d"),IF(AND(ISBLANK(AdmitDate),ISBLANK(DischargeDate)),0,"")))

enter image description here

OTHER TIPS

If I understood your requirements correctly (correct me if I am wrong), this is what you are looking for:

IF(ISBLANK([Date Discharged]),DATEDIF([Date Admitted to Hospital],TODAY(),"d"),DATEDIF([Date Admitted to Hospital],[Date Discharged],"d")) 

Microsoft official documentation:

Calculate the difference between two dates

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top