Sum if based on ranges of conditions

Thomasms90

New Member
Joined
Dec 15, 2015
Messages
4
Hi all,

I need to do a SUMIF that is rather advanced compared to what I'm used to since it must compare arrays of different sizes (or match them sequentially). I can't find a way to post a screenshot nor mock file, so I hope below is understandable.

I have an array A that consists of different types a, b, c, d, e, f.

Then an array B that contains ranges (lower and upper bounds) of unique identifiers that are connected with either a, b, c, d, e, or f (i.e. 1000 to 1099 belongs to a, 1100 to 1249 belongs to a, and 3000 to 3099 belongs to a, and so forth for other types).

Finally an array C that contains a very large data range of a given identifier and an associated value.

I need to do a sumif of the values in array C, given that the identifier is within any of the given ranges in array B that are associated with a given type.

Currently, my only solution is to split it up into several formulae parts, where I have 1 SUMIFS() for each identifier in array B that matches the type in array A. But this is unfeasible in my actual workbook and very manual.

Is there a way to do this in one formula? I've tried SUM(IF()) arrays, but that won't work as it usually does, since the arrays are not of the same size.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
I can't find a way to post a screenshot

Go here: https://onedrive.live.com/?id=8CFFDE...FFDEC0CE27E813

download the first folder, extract, then go to file-options-add ins-manage add ins-browse-click on the file wherever you saved it-be sure it's checked in the add ins, and it should appear on the ribbon if you have Excel 2007 or later, otherwise in the tools menu.

To post on the board with it, highlight the range (not too large, there's like a 100 row limit and too many columns are hard to see), then go to add-ins - mrexcel htlml - generate html - go to MrExcel message page and control-V
 
Last edited:
Upvote 0
Go here: https://onedrive.live.com/?id=8CFFDE...FFDEC0CE27E813

download the first folder, extract, then go to file-options-add ins-manage add ins-browse-click on the file wherever you saved it-be sure it's checked in the add ins, and it should appear on the ribbon if you have Excel 2007 or later, otherwise in the tools menu.

To post on the board with it, highlight the range (not too large, there's like a 100 row limit and too many columns are hard to see), then go to add-ins - mrexcel htlml - generate html - go to MrExcel message page and control-V

I'm on a corporate computer so I can't install any addins or third party software, unfortunately :(
 
Upvote 0
Ok - something like below, where array C is just very long and array B may change over time.

I need to sum the values in array C that corresponds to the Lower bounds and upper bounds (LB and UB) in Array B for each type in Array A. Hence, there is in most cases several ranges for each type.

Code:
Array A: Sums		Array B: Identifiers		Array C: Data range	
Type	Sum		LB	UB	Type		ID	Value
a	17.859.514	1000	1099	a		1000	94.320
b			1100	1249	a		1001	73.011
c			1250	1499	f		1002	74.188
d			1500	1519	e		1003	11.627
e			1520	1599	c		1004	48.696
f			1600	1699	d		1005	58.817
			1700	1999	b		1006	44.725
			2000	2499	c		1007	11.037
			2500	2999	e		1008	1.992
			3000	3099	a		1009	30.449
			3100	3499	f		1010	70.497
							1011	93.524
							1012	69.277
							1013	79.498
							1014	72.081
 
Upvote 0
Hi
Copying your data into my workbook and parsing it, I ended up with the LB's in column D starting at D3, and UB's in column E starting at E3.

ID started in H3 and Value in I3

With a to f in A3:A8 the following formula in B3 and copied down should give your desired results.
Sumifs can take whole columns as the objects, and there are only 2 columns of interest, ID and Value
=SUMIFS(I:I,H:H,">="&D3,H:H,"<="&E3)
 
Upvote 0
Hi
Copying your data into my workbook and parsing it, I ended up with the LB's in column D starting at D3, and UB's in column E starting at E3.

ID started in H3 and Value in I3

With a to f in A3:A8 the following formula in B3 and copied down should give your desired results.
Sumifs can take whole columns as the objects, and there are only 2 columns of interest, ID and Value
=SUMIFS(I:I,H:H,">="&D3,H:H,"<="&E3)

Hi Roger,

Thanks for your reply, but it does not solve my issue, unfortunately. The complication is exactly that I have the Array B in which there may or may not be several ranges that I need to sum, depending on the type of the object.

For type a it would need to sum the values in your column I whenever the ID is in the ranges 1000<=X<=1099, 1100<=X<=1249, and 3000<=X<=3099.
 
Upvote 0
A very simple solution is to use a Helper column. Something like this


A
B
C
D
E
F
G
H
I
1
Type​
Sum​
LB​
UB​
Type​
Helper​
ID​
Value​
2
a​
833.739​
1000​
1099​
a​
833739​
1000​
94.320​
3
b​
1100​
1249​
a​
0​
1001​
73.011​
4
c​
1250​
1499​
f​
0​
1002​
74.188​
5
d​
1500​
1519​
e​
0​
1003​
11.627​
6
e​
1520​
1599​
c​
0​
1004​
48.696​
7
f​
1600​
1699​
d​
0​
1005​
58.817​
8
1700​
1999​
b​
0​
1006​
44.725​
9
2000​
2499​
c​
0​
1007​
11.037​
10
2500​
2999​
e​
0​
1008​
1.992​
11
3000​
3099​
a​
0​
1009​
30.449​
12
3100​
3499​
f​
0​
1010​
70.497​
13
1011​
93.524​
14
1012​
69.277​
15
1013​
79.498​
16
1014​
72.081​
17

Formula in G2 (Helper) copied down
=SUMIFS(I:I,H:H,">="&D2,H:H,"<="&E2)

Formula in B2 copied down
=SUMIF(F:F,A2,G:G)

Hope this helps

M.
 
Upvote 0
Hi Thomas

Sorry, I had not noticed that column F (in my data set) was not a contiguous range of a ... f
I see that there are several discontiguous range than belong to a, etc.

That being the case, the only solution I can see is a manual addition of Sumifs formulae
=SUMIFS(I:I,H:H,">="&D3,H:H,"<="&E3)+SUMIFS(I:I,H:H,">="&D4,H:H,"<="&E4)+SUMIFS(I:I,H:H,">="&D12,H:H,"<="&E12)

Obviously such a formula cannot be dragged down and would have to be constructed for each cell in B3:B8

What would be better would be to set up a lookup table, and use an extra column.
I set up a table in cells K1:L12 to hold my lookup table (pasted here horizontally for convenience)
K1 holds 0 and L1 holds a etc. L12 is blank

01249149915191599169919992499299930993499
afecdbceaf


<colgroup><col width="72" span="11" style="width:54pt"> </colgroup><tbody>
</tbody>
Then in column J, starting in J3 the formula
=VLOOKUP(H3,$K$1:$L$11,2,1) and copied down

In B3 the formula then becomes simply a SUMIF formula as follows
=SUMIF(J:J,A3,I:I)
copied down through B4:B8
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,517
Members
448,968
Latest member
Ajax40

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