Question re: SUMIFS and Arrays

masouder

Board Regular
Joined
Jul 5, 2013
Messages
111
Office Version
  1. 2013
Platform
  1. Windows
I am using the SUMIFS functions function with multiple array criteria and have a question about using semi-colons versus commas in the arrays. The following formula using commas in the first criteria incorrectly returns zero:

Excel Formula:
=SUM(SUMIFS(RevenueYearToDateRevenues,RevenueFund,{"222","26*","27*"},RevenueObjectCode,{"4010*","4230*"}))

The following formula using semi-colons in the first criteria returns the correct result:

Excel Formula:
=SUM(SUMIFS(RevenueYearToDateRevenues,RevenueFund,{"222";"26*";"27*"},RevenueObjectCode,{"4010*","4230*"}))

Can anyone explain why semi-colons work and commas do not? Also, how would I handle this if there was a third criteria? Lastly, is there a better formula to use?
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
When using two sets of multiple criteria, one must be horizontal (using commas) & one must be vertical (using semi-colons).
You can only have two sets of multiple criteria.
 
Upvote 0
When you create an array constant with commas, it is a horizontal array. When you create an array constant with semicolons, it is a vertical array. The process Excel uses internally to combine the arrays is different based on the type of arrays. For example, if you have

Excel Formula:
=SUM(SUMIFS(rng1,rng2,{"a","b"},rng3,{1,2}))

then Excel calculates
Excel Formula:
SUMIFS(rng1,rng2,"a",rng3,1)
Excel Formula:
SUMIFS(rng1,rng2,"b",rng3,2)

and sums them. Since the arrays are in the same orientation, it assumes that the elements of each array match up with each other. So you'd miss the a,2 and b,1 combinations. If you use a comma on one of the array constants, and the semicolon on the other, then Excel creates an internal 2-D array with every combination in the 2-D array, and sums that.

When you have 2 arrays with the same orientation of different sizes, even stranger things can happen.

So no, you can't use the SUM(SUMIFS construct with more than 2 array constants. Excel only handles 2-D arrays. If you want to use more than 2 ranges with multiple values, you could do something like:

Excel Formula:
=SUMPRODUCT(sumrange,--ISNUMBER(MATCH(range1,{"a","b","c"},0)),--ISNUMBER(MATCH(range2,{1,2},0)),--ISNUMBER(MATCH(range3,{"Amy","Bob","Cal","Deb"},0)))

Using actual ranges on your workbook for the array constants would probably be neater though, and allow for easier changes.
 
Upvote 0
Eric, actually I spoke too soon. I tried the formula and it did not appear to work. Can you tell me what is wrong with the below formula?

Excel Formula:
=SUMPRODUCT(RevenueYearToDateRevenues,--ISNUMBER(MATCH(RevenueFund,{"222","26*","27*"},0)),--ISNUMBER(MATCH(RevenueObjectCode,{"4010*","4230*"},0)))
 
Upvote 0
It's the wildcards. Wildcards don't work with MATCH. You might have to break up each condition separately, and do something like this:

Book1
ABCDE
1
2
312224010132
422614230ab
5377740102
6426240103
751114230x
86277423022
97abxx
108
11922242305
121026642305
13
Sheet1
Cell Formulas
RangeFormula
E3E3=SUMPRODUCT(RevenueYearToDateRevenues,SIGN((RevenueFund=222)+(LEFT(RevenueFund,2)="26")+(LEFT(RevenueFund,2)="27")),SIGN((LEFT(RevenueObjectCode,4)="4010")+(LEFT(RevenueObjectCode,4)="4230")))
Named Ranges
NameRefers ToCells
RevenueFund=Sheet1!$B$3:$B$12E3
RevenueObjectCode=Sheet1!$C$3:$C$12E3
RevenueYearToDateRevenues=Sheet1!$A$3:$A$12E3


It's worth mentioning that the FILTER function in newer versions of Excel might make it a bit easier, but you'd still have to list each condition separately. There might be some ways to simplify this a bit depending on the characteristics of your data (for example, are the RevenueFund values all 3 digits?), but I don't see any great way to simplify it. If you only have two columns to check, the SUM(SUMIFS( with 2 array constants is probably the cleanest. With more than two columns, you have to do something like this example.
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,591
Members
449,089
Latest member
Motoracer88

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