Formula to calculate the number of days occurring in multiple date ranges for different individuals

C_Har

New Member
Joined
Sep 29, 2016
Messages
5
Hello,

I am trying to develop an Excel formula that allows me to count the number of days occurring within two date ranges for different individuals. Here is a sample of my dataset:

id
admDt
sepDt
admDur

id
dxDt-1
dxDt
admDurTot
1
16/01/2000
18/01/2000
2

1
24/01/2000
24/02/2000
28
1
22/01/2000
18/02/2000
27

2
30/03/2000
30/04/2000
0
1
20/02/2000
22/02/2000
2

3
03/02/2000
03/03/2000
0
1
24/02/2000
28/02/2000
4

4
31/12/1999
31/01/2000
0
5
19/05/2000
20/06/2000
32

5
20/05/2000
20/06/2000
31
8
25/12/1999
28/12/1999
3

6
13/11/2000
13/12/2000
0
8
18/01/2000
26/01/2000
8

7
14/04/2000
14/05/2000
0
8
28/01/2000
28/01/2009
3288

8
23/12/1999
23/01/2000
9





9
09/02/2000
09/03/2000
0

<tbody>
</tbody>

For columns A-D, each row reflects an event (in this case, a hospital admission):
id = individual's ID number
admDt = date of admission
sepDt = date of discharge
admDur = duration (in days) of admission

Please note that multiple rows can relate to one individual (e.g., A2:E5).

For columns F-I, each row reflects one individual's data:
id = individual's ID number
dxDt-1 = date one month preceding diagnosis
dxDt = date of diagnosis
admDurTot = total duration (in days) of admission

Date ranges for each admission (admDt and sepDt) and individual (dxDt-1 and dxDt) can be different. While the date ranges for each event may span across months (e.g., cells A3:C3 or A9:C9), I am interested in calculating the number of days the person spent in hospital (admDurTot) in the month preceding their diagnosis (dxDt).

Please note that the values in admDurTot reflect those I would like to obtain, rather than those obtained from different formulae I have used.

I have tried variations of the SUMIFS formula:
• = SUMIFS($D:$D, $A:$A, $G2, $B:$B, ">=" & $H2, $C:$C, "<=" & $I2)
• = SUMIFS($D:$D, $A:$A, $G2, $B:$B, "<=" & $I2, $C:$C, ">=" & $H2)
• = SUMIFS($D:$D, $A:$A, $G2, $B:$B, ">=" & $H2, $C:$C, ">" & $H2, $C:$C, "<=" & $I2)

However, they are confounded by the fact that both admDt and sepDt often fall outside the range of interest (i.e., they are not between dxDt-1 and dxDt). For example, in the case of individual 1, the above formulae indicate that he spent 33 days in hospital in the month preceding his diagnosis. In reality, he spent 28 days in hospital during that period.

I have found little guidance on other websites. I have reviewed the following link; however, the formula provided is not quite appropriate for my needs.

http://www.mrexcel.com/forum/excel-questions/851273-counting-number-overlapping-days-between-multiple-date-ranges.html


Any assistance would be greatly appreciated.
 
Re: Excel: Formula to calculate the number of days occurring in multiple date ranges for different individuals

A very delayed response; I moved to R to conduct my analysis, but returned to this to assist a colleague using Excel. The formula functions correctly; the reason I could not use it initially was that I matched it to G:G, rather than A:A.

Many thanks for your help.
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,215,453
Messages
6,124,921
Members
449,195
Latest member
Stevenciu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top