I found an old post that I think is interesting to write about today. Think of two overlapping ranges, it may be dates, times or whatever, the formula demonstrated here works with everything.
This picture shows two time ranges, 06:00-13:00 (yellow) and 11:00-18:00 (green).
It is obvious that there are two overlapping hours but how do we calculate it in excel?
The MEDIAN function comes to rescue, but first let me explain the function. It returns a value that separates the higher half of a data set from the lower half. Example, MEDIAN(1,2,3) returns 2. 1 is the lower half and 3 is the higher half.
MEDIAN(1,2,3,4,5,6) returns 3.5 because there are two values (3, 4) separating the higher half (5,6) from the lower half (1,2). The average of these two values is 3.5.
Calculate overlapping hours
We have 4 times here to remember, the start and end of time range 1 and 2.
Let see what happens if we use the MEDIAN function with the start and end value of time range 1 and only the start value of time range 2.
MEDIAN("06:00", "13:00", "11:00") returns 11:00.
And then the end of time range 2.
MEDIAN("06:00", "13:00", "18:00") returns 13:00
13:00 - 11:00 is 02:00. Two hours are overlapping.