This article explains how to build an array formula that sums ranges. Example, I want to know how to calculate the total sum between x.2 -x.3 and x.5-x.8 and the range is 0.5 and 4.5.

This picture shows you how to manually sum the ranges x.2-x.3 and x.5-x.8 between 0.5 and 4.5.

sum numerical ranges

The range starts at 0.5 so 0.2-0.3 is 0. 0.5-0.8 is  0.3. Total sum between 0.5-1 is 0.3.
1.2-1.3 is 0.1 and 1.5-1.8 is 0.3. Total sum between 1-2 is 0.4.
2.2-2.3 is 0.1 and 2.5-2.8 is 0.3. Total sum between 2-3 is 0.4.
3.2-3.3 is 0.1 and 3.5-3.8 is 0.3. Total sum between 3-4 is 0.4.
4.2-4.3 is 0.1 and 4.5-4.8 is 0 because the range ends at 4.5. Total sum between 4-4.5 is 0.1.

sum numerical ranges - frequency4

The grand total is 1.6 (0.3+0.4+0.4+0.4+0.4+0.1 = 1.6).

Building the array formula

First task is to build an array that returns this range 0.5 to 4.5 with increments by 0.1, like this {0.6; 0.7; ... 4.3; 4.4; 4.5}.

C3+ROW($A$1:INDEX($A:$A, (D3-C3)*10))/10

We only need the decimal part of the values in this array.

=ROUND(MOD(C3+ROW($A$1:INDEX($A:$A, (D3-C3)*10))/10, 1), 1)

The array becomes {0.6; 0.7; ... 0.3; 0.4; 0.5}

The MOD function returns the decimal part of a number, unfortunately it returns a floating point error. The ROUND function takes care of that.

Second task is to build the ranges. We are going to use the FREQUENCY function and therefore we need to be more specific regarding the ranges.

sum numerical ranges - frequency

The picture shows not only 0.2-0.3 and 0.5-0.8 but also other ranges before, between and after. We are not interested in those ranges but they are required in order to get the FREQUENCY function to work as we want.

It is now time to use the frequency function with our array and our ranges:

=FREQUENCY(ROUND(MOD(C3+ROW($A$1:INDEX($A:$A, (D3-C3)*10))/10, 1), 1), $C$15:$C$19)/10

sum numerical ranges - frequency1

The array formula returns an array shown in D15:D20. The range we are using is 0.5 to 4.5, remember? 4.5 - 0.5 is 4. 4 is supposed to be equal to the sum of the frequency values in D15:D20. Lets verify that, 1.2+0.4+0.8+1.2+0.4 = 4. Correct.

The third task is to sum the ranges we need. In order to do that I have built a new column "Count", 1 for a range I want in the sum and 0 for a range I don´t want.

sum numerical ranges - frequency2

Lets multiply the array formula with the "Count" column (E15:E19):

sum numerical ranges - frequency3

=(FREQUENCY(ROUND(MOD(C3+ROW($A$1:INDEX($A:$A, (D3-C3)*10))/10,1),1), $C$15:$C$19)/10)*E15:E20

This formula returns {0; 0.4; 0; 1.2; 0; 0}.

Then use the SUM function to sum the values in the array:

=SUM((FREQUENCY(ROUND(MOD(C3+ROW($A$1:INDEX($A:$A, (D3-C3)*10))/10,1),1), $C$15:$C$19)/10)*E15:E20)

returns 1.6. 0.4 + 1.2 is 1.6, it matches the manual calculation we did in the beginning of this blog post.

Final thoughts

Why would you want to sum numerical ranges? Consider that date and time values are actually numbers in excel, get it?

Download excel *.xlsx file

Sum numerical ranges.xlsx