max of sumifs of multiple columns

peledan

New Member
Joined
Dec 16, 2012
Messages
4
Hi All,
I'm new here, so sorry for any newb mistakes...

I'm trying to find the max between sumifs of multiple adjacent columns in a range, meaning something like this:
=max(sumifs(A1:A5, criteriaRange1, criteria1...), sumifs(B1:B5, criteriaRange1, criteria1...), sumifs(C1:C5, criteriaRange1, criteria1...), etc.)
But obviously without the commas, as I have a lot of columns to sum over.
I cannot use a helper line, as I have many possible changing criteria.
I tried to do it with an array function, and googled it for hours, but without success.
I was hoping for something like:
{=max(sumifs(A1:C5, criteriaRange1, criteria1...)}
But this obviously doesn't work as it just sums over the entire range and not per-column.

Any help would be appreciated!
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Excel Workbook
ABCDEF
114502020A
225553020B
336604020B
447655520B
558706020C
6
7B
8180180
3aa
Excel 2003
Cell Formulas
RangeFormula
A8=MAX(SUMIF(F1:F5,A7,A1:A5),SUMIF(F1:F5,A7,B1:B5),SUMIF(F1:F5,A7,C1:C5),SUMIF(F1:F5,A7,D1:D5),SUMIF(F1:F5,A7,E1:E5))
B8=MAX(SUMIF(F1:F5,A7,OFFSET(A1:E5,,{0,1,2,3,4})))


N.B.

This is a quick guess.

If you provide a concise example, someone may be able to provide additional help.

Dave
 
Upvote 0
First of all thanks for the help,
I still cannot expand your solution to what I need (whatever I try doesn't work),
So I will post my full problem as you suggested.
Similarly to your example, this is what I need:
ABCDEF
1145020AA
A
2255530AA
B
3366040BB
B
4476555BB
B
5587060BB
C
6
7
8

<tbody>
</tbody>

What I need is the maximum sum of columns A-D, for which Col E = AA and col F = (A or B), for example.
In this case it is 105 from Col C.

3aa
ABCDEF
114502020A
225553020B
336604020B
447655520B
558706020C
6
7B
8180180

<thead>
</thead><tbody>
</tbody>
Excel 2003

Worksheet Formulas
CellFormula
A8=MAX(SUMIF(F1:F5,A7,A1:A5),SUMIF(F1:F5,A7,B1:B5),SUMIF(F1:F5,A7,C1:C5),SUMIF(F1:F5,A7,D1:D5),SUMIF(F1:F5,A7,E1:E5))
B8=MAX(SUMIF(F1:F5,A7,OFFSET(A1:E5,,{0,1,2,3,4})))

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>



N.B.

This is a quick guess.

If you provide a concise example, someone may be able to provide additional help.

Dave
 
Upvote 0
Try:

=MAX(SUMPRODUCT(--(E1:E5="AA"),((F1:F5="A")+(F1:F5="B")),A1:A5),SUMPRODUCT(--(E1:E5="AA"),((F1:F5="A")+(F1:F5="B")),B1:B5),SUMPRODUCT(--(E1:E5="AA"),((F1:F5="A")+(F1:F5="B")),C1:C5),SUMPRODUCT(--(E1:E5="AA"),((F1:F5="A")+(F1:F5="B")),D1:D5))
 
Upvote 0
Excel Workbook
ABCDEF
1145020AAA
2255530AAB
3366040BBB
4476555BBB
5587060BBC
6
7AAAB
8105105
9
3aaa
Excel 2003
Cell Formulas
RangeFormula
E8=SUMPRODUCT(C1:C5,--(E1:E5=A7),--((F1:F5=B7)+(F1:F5=C7)))
F8=MAX(SUMPRODUCT(A1:A5,--(E1:E5=A7),--((F1:F5=B7)+(F1:F5=C7))),SUMPRODUCT(B1:B5,--(E1:E5=A7),--((F1:F5=B7)+(F1:F5=C7))),SUMPRODUCT(C1:C5,--(E1:E5=A7),--((F1:F5=B7)+(F1:F5=C7))),SUMPRODUCT(D1:D5,--(E1:E5=A7),--((F1:F5=B7)+(F1:F5=C7))))


This gives the answer but it is a bit long.

Dave
 
Upvote 0
Try this version

=MAX(MMULT(SUMIFS(OFFSET(A1:A5,0,{0;1;2;3}),E1:E5,"AA",F1:F5,{"A","B"}),{1;1}))

This works specifically when you have a single criterion in one column but two in another - {0;1;2;3} dictates the number of sum columns - change as required
 
Upvote 0
Thanks for all the replies!
Andrew and Dave, your solutions are great, but not quite what I need, as their length is pretty proportional to the number of columns I'm summing over, which was the main original problem.

Barry, first of all, wow. This is such an elegant solution, and exactly the kind of thing I needed.
It works great, but if you have a min, I'd like to ask a thing or two about it, as I'm here to learn :)
1) What's the difference between inserting an array separated with commas and semicolons?
2) Why doesn't it need to be entered as an array function?
3) Can I somehow replace the {0;1;2;3} with a function returning this, such as the way COLUMN(A1:A4) as an array function returns {1,2,3,4}?

Thanks!
 
Upvote 0
By having one set of values which is a "column" and one which is a "row" then the overall result is a matrix which is as long as the column and as wide as the row. You can see how it works by typing this in a cell

=A1:A4

now select the cell and press F9 and you see the values in those cells separated by semi-colons, e.g. if all values in the range were 3s then you'd see

{3;3;3;3}

...so by using this part

OFFSET(A1:A5,0,{0;1;2;3})

that returns an array of each of the four columns, but acting as a column of values....and by having the last criterion comma-separated like
{"A","B"} then the result of the SUMIFS function is a 4 row x 2 column matrix, where the first column is the result for "A" and the second column is the result for "B", so in your example the result is

{1,2;4,5;50,55;20,30}

...but you need to combine the "A" and "B" values for each row.....and MMULT can do that

=MMULT({1,2;4,5;50,55;20,30},{1;1}) = {3;9;105;50}

and then MAX just gives you the MAX, i.e. 105

Typically you don't have to array enter if you use "array constants" like {0;1;2;3}, as in my example, but if you use a calculation which generates that array then it will need CTRL+SHIFT+ENTER.

So this version will do the same (array entered)

=MAX(MMULT(SUMIFS(OFFSET(A1:A5,0,ROW(INDIRECT("1:4"))-1),E1:E5,"AA",F1:F5,{"A","B"}),{1;1}))

with this part

=ROW(INDIRECT("1:4"))-1

generating the required {0;1;2;3}

so for 26 columns you could use

=ROW(INDIRECT("1:26"))-1

or you can specifically use the range like

=TRANSPOSE(COLUMN(A1:Z1)-1)

[you need TRANSPOSE because we need to have a column of values not a row]
 
Last edited:
Upvote 0
Fabulous answer Barry!
I've learned so many things from it that I didn't even know existed in excel...
Thanks!
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,276
Members
449,075
Latest member
staticfluids

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