hi all,
just need a tidier way of getting my days allocated to the months in which they fall. my data represents the duration of stay for patients in hospital. I have an admission date and a discharge date (in most cases). I am using the following formula to distribute the total number of days to the months in which the patient stayed.
Header row: 4
Admission Date: $c5
Discharge Date: $E5
$AB$4:$AY$4: Month names from July to June (for two years. ie Financial years ending June 30,2018)
$AB$2:$AY$2: end of each month named in Row 4
$AB$3:$AB$3: first day of each month
For the example, I am using an admission date of May 2, 2017 and discharge date May 4, 2017.
The formula i have so far is:
=IF($C5>AC$2,0,
IF($E5<AC$3,0,
IF(AND($E5=AC$3,$C5<=AB$2),0,
IF(AND($C5<AC$3,$E5<=AC$2),$E5-AC$3,
IF($E5=$C5,1,
IF($C5<=AB$2,AC$2-AC$3+1,
IF(AND($C5>=AC$3,$E5<=AC$2),$E5-$C5,AC$2-$C5+1)))))))
with the following logic:
=IF($C5>AC$2,0, '''''''if the Admission Date is past current month end, 0 days, ELSE
IF($E5<AC$3,0, ''''''''if the Discharge Date is prior to the current month, 0 days, ELSE
IF(AND($E5=AC$3,$C5<=AB$2),0, '''''if the Discharge Date = the first day of month AND Admission Date is equal to or before the end of the previous month, 0 days, ELSE
IF(AND($C5<AC$3,$E5<=AC$2),$E5-AC$3, '''''''if Admission Date is before start of month AND Discharge is before or equal to month end, Discharge Date minus Start of month, ELSE
IF($E5=$C5,1, '''''if Admission and Discharge dates are equal, 1 day, ELSE
IF($C5<=AB$2,AC$2-AC$3+1, '''''if Admission date is before or equal to the end of the previous month, end of current month minus start of current month plus 1 day, ELSE
IF(AND($C5>=AC$3,$E5<=AC$2),$E5-$C5,AC$2-$C5+1))))))) '''''if Admission Date is greater than or equal to start of current month AND Discharge is less than or equal to month end, then Discharge Date minus Admission Date, ELSE end of current month minus Admission Date plus 1 day
I think the only thing i have not accounted for and can't seem to add in the right place is those patient stays when there is no Discharge Date at the time of the report run. In these situations, if, the Admission Date is prior to the start of the current month, the current month's value should be EOMONTH - Start of Month, and if its within the current month, the value to show would be the EOMonth date minus Admission Date.
any suggestions?
just need a tidier way of getting my days allocated to the months in which they fall. my data represents the duration of stay for patients in hospital. I have an admission date and a discharge date (in most cases). I am using the following formula to distribute the total number of days to the months in which the patient stayed.
Header row: 4
Admission Date: $c5
Discharge Date: $E5
$AB$4:$AY$4: Month names from July to June (for two years. ie Financial years ending June 30,2018)
$AB$2:$AY$2: end of each month named in Row 4
$AB$3:$AB$3: first day of each month
For the example, I am using an admission date of May 2, 2017 and discharge date May 4, 2017.
The formula i have so far is:
=IF($C5>AC$2,0,
IF($E5<AC$3,0,
IF(AND($E5=AC$3,$C5<=AB$2),0,
IF(AND($C5<AC$3,$E5<=AC$2),$E5-AC$3,
IF($E5=$C5,1,
IF($C5<=AB$2,AC$2-AC$3+1,
IF(AND($C5>=AC$3,$E5<=AC$2),$E5-$C5,AC$2-$C5+1)))))))
with the following logic:
=IF($C5>AC$2,0, '''''''if the Admission Date is past current month end, 0 days, ELSE
IF($E5<AC$3,0, ''''''''if the Discharge Date is prior to the current month, 0 days, ELSE
IF(AND($E5=AC$3,$C5<=AB$2),0, '''''if the Discharge Date = the first day of month AND Admission Date is equal to or before the end of the previous month, 0 days, ELSE
IF(AND($C5<AC$3,$E5<=AC$2),$E5-AC$3, '''''''if Admission Date is before start of month AND Discharge is before or equal to month end, Discharge Date minus Start of month, ELSE
IF($E5=$C5,1, '''''if Admission and Discharge dates are equal, 1 day, ELSE
IF($C5<=AB$2,AC$2-AC$3+1, '''''if Admission date is before or equal to the end of the previous month, end of current month minus start of current month plus 1 day, ELSE
IF(AND($C5>=AC$3,$E5<=AC$2),$E5-$C5,AC$2-$C5+1))))))) '''''if Admission Date is greater than or equal to start of current month AND Discharge is less than or equal to month end, then Discharge Date minus Admission Date, ELSE end of current month minus Admission Date plus 1 day
I think the only thing i have not accounted for and can't seem to add in the right place is those patient stays when there is no Discharge Date at the time of the report run. In these situations, if, the Admission Date is prior to the start of the current month, the current month's value should be EOMONTH - Start of Month, and if its within the current month, the value to show would be the EOMonth date minus Admission Date.
any suggestions?