SUMIFS With Multiple Criteria In One Column

excelbytes

Active Member
Joined
Dec 11, 2014
Messages
291
Office Version
  1. 365
Platform
  1. Windows
I have a formula that works to sum up the data with multiple criteria in one column:

=SUM(SUMIFS(DATA!$I:$I,DATA!$C:$C,$A$10,DATA!$G:$G,F$4,DATA!$E:$E,$A$20:$A$27,DATA!$A:$A,$B$2,DATA!$F:$F,$B$1))

However, I have a need to multiple criteria in each of two columns:

=SUM(SUMIFS(DATA!$I:$I,DATA!$C:$C,$A$10:$A$17,DATA!$G:$G,F$4,DATA!$E:$E,$A$20:$A$27,DATA!$A:$A,$B$2,DATA!$F:$F,$B$1))

But that doesn't work. Is there a way to accomplish this? If not with a formula, is there a VBA solution?
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try this:
Excel Formula:
=SUM(SUMIFS(DATA!$I:$I,DATA!$C:$C,TRANSPOSE($A$10:$A$17),DATA!$G:$G,F$4,DATA!$E:$E,$A$20:$A$27,DATA!$A:$A,$B$2,DATA!$F:$F,$B$1))
 
Upvote 0
Solution
Try this:
Excel Formula:
=SUM(SUMIFS(DATA!$I:$I,DATA!$C:$C,TRANSPOSE($A$10:$A$17),DATA!$G:$G,F$4,DATA!$E:$E,$A$20:$A$27,DATA!$A:$A,$B$2,DATA!$F:$F,$B$1))
It works perfectlym Thanks! Can you explain why?
 
Upvote 0
It works perfectlym Thanks! Can you explain why?
Actually, there is an issue. It worked fine until I added more criteria. See below. When I had Ball and Crown in the Customers, it was fine, but when I added Springs, it didn't include those in the totals. I'm guessing it can only handle items in a certain order. Can you explain?

SUMIFS Multi Criteria.xlsm
ABCDEFGHIJKLMNOP
1CoAccounts AOP FileCorporate NameAccount NameItem GroupAccount ManagerMonthQuarterForecast
2SpringsSparesApr-2485000
3BallCompApr-2460000
4CrownSparesApr-2437500
5BallCompApr-2425000
6BallCompApr-2424000
7Crown SparesApr-2415400
8CrownCompApr-2415000
9CustomerCrownCompApr-2412000
10BallCrownCompApr-2410000
11CrownCrownCompApr-2410000
12SpringsBallCompApr-248400
13CrownCompApr-246000
14BallSparesApr-245000
15CrownCompApr-245000
16CrownCompApr-242500
17CrownSparesApr-242000
18SpringsComp. SparesApr-241500
19Groups
20Comp
21Spares
22
23
24
25
26
27
28
Sheet1
 
Upvote 0
SUMIFS will allow up to two “OR”-type criteria, but the criteria need to be expressed differently: one as a horizontal array, the other as a vertical array. Otherwise, SUMIFS would have no way of handling the two sets of OR conditions. Taking your original formula as an example, where you had A20:A27, SUMIFS treats this as a single vertical array consisting of 8-elements (rows), and the other criteria in SUMIFS (the other AND conditions) are applied to each of these rows, for a total of 8 sets of logical AND conditions that are applied to the data found on the DATA sheet. So SUMIFS returns 8 sums, and these are finally wrapped in a SUM function to obtain the grand total.

If you then want a 2nd set of OR conditions, we can't use another vertical array because there would be ambiguity regarding how the expression should be interpreted. Instead, the criteria array is transposed to create a single row array (TRANSPOSE(A20:A27)...so a single row, 8-column array), and the other criteria in SUMIFS, including the other "OR" criteria, are applied to each of these columns, to effectively generate a set of 64 logical expressions that are applied to the data in the DATA sheet. And the resulting 64 sums from the SUMIFS functions are summed together by the SUM wrapper function.

This method should work because it exploits SUMIFS ability to handle two-dimensional arrays; however, a 3rd OR condition would require a different approach.

I don't see any problem with the example you posted. You've shifted some columns, so the formula above needs some adjustment. Have a look at this example...compare the manual sum checked in P1 of DATA with the formula result in C6 of Sheet1.
MrExcel_20240108.xlsx
ABCDEF
1Data L critb
2Data A crit12a
3
4Data M crit4/1/2024
5
611Result summing Data O29
7
8
9Customer
10BallData I crit (single)
11CrownData I crit (expanded)
12Springs
13
14
15
16
17
18
19Groups
20CompData K crit
21Spares
22
23
24
25
26
27
Sheet1
Cell Formulas
RangeFormula
A6A6=SUM(SUMIFS(DATA!$O:$O,DATA!$I:$I,$A$10,DATA!$M:$M,F$4,DATA!$K:$K,$A$20:$A$27,DATA!$A:$A,$B$2,DATA!$L:$L,$B$1))
C6C6=SUM(SUMIFS(DATA!$O:$O,DATA!$I:$I,TRANSPOSE($A$10:$A$17),DATA!$M:$M,F$4,DATA!$K:$K,$A$20:$A$27,DATA!$A:$A,$B$2,DATA!$L:$L,$B$1))

MrExcel_20240108.xlsx
AIJKLMNOP
1Corporate NameItem GroupAccount ManagerMonthForecast29
212aSpringsSparesbApr-241
312aBallCompbApr-242
412aCrownSparesbApr-243
512aBallCompbApr-244
612aBallCompbApr-245
712aCrownSparesbApr-246
822bCrownCompbApr-247
912aCrownCompbApr-248
1022bCrownCompbApr-249
11CrownCompbApr-2410
12BallCompbApr-2411
13CrownCompbApr-2412
14BallSparesbApr-2413
15CrownCompbApr-2414
16CrownCompbApr-2415
17CrownSparesbApr-2416
18SpringsComp. SparesbApr-2417
DATA
Cell Formulas
RangeFormula
P1P1=SUM(O2:O7,O9)
 
Upvote 0
I think this is working correctly. I need to spend more time analyzing it. This is a 90 Mb file and it may just be an issue with some corrupt data. Thanks again for all your help.
 
Upvote 0
I'm happy to help. Post back if you discover any surprises. I've tested further with the small example above--by excluding items in each of the AND conditions and adding additional OR match items to "Customer" and "Groups"...and then comparing the formula results to a manual sum. I haven't encountered any discrepancies.
...it may just be an issue with some corrupt data
This is definitely something to consider. An extra space or misspelling will exclude items that otherwise would be included.
 
Upvote 0
One last question (I hope)...

Here is my final formula which is working:

=IF(A4="CORPORATE CUSTOMER",SUM(SUMIFS('AOP DATA'!$I:$I,'AOP DATA'!$C:$C,TRANSPOSE($A$10:$A$14),'AOP DATA'!$G:$G,F$4,'AOP DATA'!$E:$E,$A$17:$A$21,'AOP DATA'!$A:$A,$B$2,'AOP DATA'!$F:$F,$B$1)),SUM(SUMIFS('AOP DATA'!$I:$I,'AOP DATA'!$D:$D,TRANSPOSE($A$10:$A$14),'AOP DATA'!$G:$G,F$4,'AOP DATA'!$E:$E,$A$17:$A$21,'AOP DATA'!$A:$A,$B$2,'AOP DATA'!$F:$F,$B$1)))

Is it possible to have an IF function inside a SUMIFS function? What I'm trying to accomplish is, for example, one of the components of the formula is:

'AOP DATA'!$F:$F,$B$1

In this scenario, $B$1 is a list of employees. On that list, I have a selection "All". What I want to do is say, if $B$1 = "All" ignore this criteria range and criteria, else use the criteria range and criteria indicated. I've done this type of thing before with only one option of "All", which is have an IF statement up front that has one formula with that criteria range and criteria and the other without, based on that selection. But I may have more than one is this scenario, so I thought if I can imbed IF statements in the SUMIFS formula, that could work.
 
Upvote 0
Yes, that should work. See this example. I've created a unique list of employees for my column L of the Data sheet and appended that list to "All" (see formula in C14). That spilling list is used in Data Validation in B1. For B1="b", a total of 48 is returned; B1="Z" yields a total of 4, and B1="All" gives 52. See how the wildcard is used in the embedded IF statement.
MrExcel_20240108.xlsx
ABCDEF
1Data L critAll
2Data A crit12a
3
4Data M crit4/1/2024
5
60Result summing Data O52
7
8
9Customer
10BallData I crit (single)
11CrownData I crit (expanded)
12Springs
13List of Employees
14All
15b
16Z
17
18
19Groups
20CompData K crit
21Spares
22Rejects
23Reinspections
24
25
26
27
Sheet1
Cell Formulas
RangeFormula
A6A6=SUM(SUMIFS(DATA!$O:$O,DATA!$I:$I,$A$10,DATA!$M:$M,F$4,DATA!$K:$K,$A$20:$A$27,DATA!$A:$A,$B$2,DATA!$L:$L,$B$1))
C6C6=SUM(SUMIFS(DATA!$O:$O,DATA!$I:$I,TRANSPOSE($A$10:$A$17),DATA!$M:$M,F$4,DATA!$K:$K,$A$20:$A$27,DATA!$A:$A,$B$2,DATA!$L:$L,IF($B$1="All","*",$B$1)))
C14:C16C14=VSTACK("All",SORT(UNIQUE(DATA!L2:L18)))
Dynamic array formulas.
Cells with Data Validation
CellAllowCriteria
B1List=$C$14#

Almost forgot...here's the Data sheet used in this example:
MrExcel_20240108.xlsx
AIJKLMNO
1Corporate NameItem GroupAccount ManagerMonthForecast
212aSpringsSparesbApr-241
312aBallCompbApr-242
412aCrownSparesbMay-243
512aBallCompZApr-244
612aBallNot CompbApr-245
712aNot CrownSparesbApr-246
822bCrownCompbApr-247
912aCrownRejectsbApr-248
1022bCrownCompbApr-249
1112aCrownRejectsbApr-2410
1222bBallCompbApr-2411
1322bCrownCompbApr-2412
1412aBallReinspectionsbApr-2413
1512aCrownRejectsbApr-2414
1622bCrownCompbApr-2415
1722bCrownSparesbApr-2416
1822bSpringsComp. SparesbApr-2417
DATA
 
Upvote 0
However when I try it on a small test sheet, I get 0 when I choose all:

=SUM(SUMIFS($K$2:$K$18,$J$2:$J$18,O2,$H$2:$H$18,TRANSPOSE($M$2:$M$9),$I$2:$I$18,$M$12:$M$19,$G$2:$G$18,IF($N$1="All","*",$N$1)))


SUMIFS Multi Criteria.xlsm
GHIJKLMNOP
1CoCorporate NameItem GroupMonthForecastCustomerAll
2100SpringsSparesApr-2485000SpringsApr-24May-24
3100SpringsCompMay-2460000Ball00
4500SpringsSparesApr-2437500
5500SpringsCompMay-2425000
6100SpringsSparesApr-2424000
7100SpringsCompMay-2415400
8500SpringsSparesApr-2415000
9500BallCompMay-2412000
10100BallSparesApr-2410000
11100BallCompMay-2410000Groups
12500BallSparesApr-248400Spares
13500BallCompMay-246000Comp
14100BallSparesApr-245000
15100BallCompMay-245000
16500BallSparesApr-242500
17500BallCompMay-242000
18100BallSparesApr-241500
19
20
Sheet1
Cell Formulas
RangeFormula
O3:P3O3=SUM(SUMIFS($K$2:$K$18,$J$2:$J$18,O2,$H$2:$H$18,TRANSPOSE($M$2:$M$9),$I$2:$I$18,$M$12:$M$19,$G$2:$G$18,IF($N$1="All","*",$N$1)))
Cells with Data Validation
CellAllowCriteria
N1List100,500,All
 
Upvote 0

Forum statistics

Threads
1,224,811
Messages
6,181,081
Members
453,021
Latest member
Justyna P

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