Adding unique days in a range

BillP

Board Regular
Joined
May 16, 2007
Messages
63
Office Version
  1. 365
  2. 2007
Platform
  1. Windows
We have a client that has to total the number of days that people received medical care (for insurance purposes). BUT...they can't count duplicate days. Some of the dates show a range of days, others only one day. They've asked for my help. (We're actually a computer services firm, but I'm pretty good with Excel...until now!)

In column C I have placed the correct totals for the date ranges, according to the payment policies. But I can't figure out how to write the formula that accommodates all the variables (mostly since all the unique dates aren't entered--only ranges).

Each line is a different medical charge, so line 1 might be 22 days of hospital stay. Line 2 is for a different charge, but covers the same dates, so it can't count. Lines 3, 4, and 5 all occur within the previously calculated range, so they don't count. The date range in line 6 is six days but 4 of them have been counted already, only 2 days fall outside an already calculated range.

It would be easy enough to do this manually for a small list, but this patient has 1367 entries in 4 months of care! And there are others that are much larger.

Fortunately, all the dates are in calendar order. Also, fortunately, they don't need line-by-line totals, just the grand total at the end of all the unique days in the range. So if I can figure out how many unique days are in the columns, I'm good.

Any ideas?

Thanks.

Bill

P.S. Sorry for the horrible layout below, I had the HTML maker in the last version of Excel, but not this one. This was quicker.


............A.................B....................C
..........Start.............End...............Total
1.....05-Aug-07.....27-Aug-07..........22
2.....05-Aug-07.....27-Aug-07........... 0 (same as a previously counted range)
3.....05-Aug-07.....05-Aug-07........... 0 (in a previously counted range)
4.....05-Aug-07.....05-Aug-07........... 0 (in a previously counted range)
5.....15-Aug-07.....22-Aug-07........... 0 (all in a previously counted range)
6.....23-Aug-07.....29-Aug-07...........2 (4 of 6 days in a previously counted range)
7.....24-Sep-07.....06-Oct-07..........13
8.....28-Sep-07.....28-Sep-07........... 0 (in a previously counted range)
9.....29-Sep-07.....29-Sep-07........... 0 (in a previously counted range)
10....18-Oct-07.....19-Oct-07...........2 (not in a previously counted range)
11....20-Oct-07.....20-Oct-07...........1 (not in a previously counted range)
12....20-Oct-07.....22-Oct-07...........2 (1 of the 3 days is in a previously counted range
....................................Total.......42
 
Last edited:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
If the start dates are sequential perhaps something like:

Excel Workbook
ABC
105-08-0727-08-0722
205-08-0727-08-070
305-08-0705-08-070
405-08-0705-08-070
515-08-0722-08-070
623-08-0729-08-072
724-09-0706-10-0713
828-09-0728-09-070
929-09-0729-09-070
1018-10-0719-10-072
1120-10-0720-10-071
1220-10-0722-10-072
Sheet5



I've not really worked through this in great detail as yet so I may have missed something obvious !
 
Upvote 0
I saw the email... RichardSchollar has replied to the Thread... and thought, after all that I'm gonna get shown up... so not as bad as normal ;)

I'll await the more elegant formulae later... will have sparked your interest now I'm guessing ... :devilish:
 
Upvote 0
Hi

Given the data in Luke's data table and the formula

=B1-A1

in C1, then in C2 the following copied down:

=SUMPRODUCT(1-ISNUMBER(MATCH(ROW(INDIRECT(A2&":"&B2)),ROW(INDIRECT(MIN($A$1:$A2)&":"&MAX($B$1:$B1))),0)))
 
Upvote 0
and there you have it... ;) ... very nice Richard... I really must get used to using the INDIRECT ROW approach for these date formulae.
 
Upvote 0
Whew!

Thank you, lasw10. I'm playing around with it now, and it even seems to work if some dates are out of order. I'll keep trying to break it and let you know.

Bill
 
Upvote 0
Wow!

I apparently have an embarrasment of riches here.

Thank you, Richard. I'm going to put that through its paces too.

Some of these reports have thousands of rows, and apparently they've been scanning them by hand to come up with a total.

You guys are the bestest!

Bill
 
Upvote 0
I actually think your first row total (in C1) should be 23 rather than 22 as it is calculated on an inclusive basis (ie the same day in both A column and B column would give a value of 1 not zero). Then you can use the following formula in C2 copied down:

=B2-MEDIAN(A2-1,MAX($B$1:$B1),B2)
 
Upvote 0
I actually think your first row total (in C1) should be 23 rather than 22 ....

I agree.

That would make the total number of unique days 43. This formula will calcuate that in a single cell

=SUM((MMULT((TRANSPOSE(A1:A12)<=ROW(INDIRECT("1:"&MAX(B1:B12)-A1+1))+A1-1)*(TRANSPOSE(B1:B12)>=ROW(INDIRECT("1:"&MAX(B1:B12)-A1+1))+A1-1),(ROW(A1:A12)>0)+0)>0)+0)

This is an array formula which must be confirmed with CTRL+SHIFT+ENTER so that curly braces appear around the formula in the formula bar

Note: Because column A in your example is sorted ascending the minimum value [i.e. earliest date] in A1:A12 is always A1. If that might not be the case you should replace A1 references in the formula with MIN(A1:A12)
 
Upvote 0

Forum statistics

Threads
1,215,737
Messages
6,126,562
Members
449,318
Latest member
Son Raphon

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