SumIfs multiple criteria & columns - UDF solution

illusionek

Board Regular
Joined
Jun 21, 2014
Messages
104
Hello

I got a challenge that requires SumIfs on steroids :) I need to be able to sum multiple columns applying two criteria on rows and one on column. The data set will be dynamic (both rows & columns) and I am unable to add helper columns. Ideally I would like to avoid array formulas due to concerns about performance but if I have no choice then beggars cant be choosers :)

I think VBA user-defined function would be ideal solutions but I struggle to come up with the correct code as my VBA skills are very limited.

First table provides example of data structure and the bottom two criteria applied and expected result.




ItemRegionJanFebMar
GrapesNorth
100​
200​
250​
GrapesSouth
50​
2​
54​
ApplesNorth
454​
54​
4​
ApplesSouth
454​
44​
44​
GrapesSouth
44​
5​
555​
ApplesNorth
4​
5​
2​




ItemGrapes
RegionSouth
MonthFeb
Expected Result
7


ItemApples
RegionNorth
MonthMar
Expected Result
6
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try

A solution using a regular formula...

Pasta1
ABCDEF
1ItemRegionJanFebMar
2GrapesNorth100200250
3GrapesSouth50254
4ApplesNorth454544
5ApplesSouth4544444
6GrapesSouth445555
7ApplesNorth452
8
9
10
11
12ItemGrapesApples
13RegionSouthNorth
14MonthFebMar
15
16Expected Result76
17
Plan1
Cell Formulas
RangeFormula
B16:C16B16=SUMIFS(INDEX($C$2:$E$7,0,MATCH(B14,$C1:$E1,0)),$A2:$A7,B12,$B2:$B7,B13)


M.
 
Upvote 0
Solution
It works well, many thanks.

Would there be any difference in performance between combination of SumIfs&Index&Match and below, which is what I managed to come up with? The main reason I was after UFD formula was due to performance concerns as I will have about 80 columns and 1000 rows. I have bad experience of using Sumproduct due to poor performance in the past.

The final report will have multiple tabs with formulas etc and my concern is that once they all start recalculating then the performance will hit the floor.


=SUMPRODUCT(C2:E7*(A2:A7=I1)*(B2:B7=I2)*(C1:E1=I3))
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,626
Members
449,093
Latest member
catterz66

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