Alternate for Array Sum Formula

tabbymulla

New Member
Joined
Aug 29, 2019
Messages
10
Can somebody please suggest an alternate to this array formula so it can calculate way faster

Code:
{=SUM(
IF(
($B$2:$B$10=$C15)*
($C$2:$C$10=$C$13)*
($D$2:$D$10=D$14)>0,
IF(
$G$2:$G$10<>"",
$G$2:$G$10,
IF(
$F$2:$F$10<>"",
$F$2:$F$10,
$E$2:$E$10))))}

I have tried below which reduces the calculation time to 1/3 but it is too much typing for the large data I am dealing with

Code:
=SUMIFS(
$G$2:$G$10,
$B$2:$B$10,$C15,
$C$2:$C$10,$C$13,
$D$2:$D$10,H$14,
$G$2:$G$10,"<>"&"")
+SUMIFS(
$F$2:$F$10,
$B$2:$B$10,$C15,
$C$2:$C$10,$C$13,
$D$2:$D$10,H$14,
$G$2:$G$10,"="&"",
$F$2:$F$10,"<>"&"")
+SUMIFS(
$E$2:$E$10,
$B$2:$B$10,$C15,
$C$2:$C$10,$C$13,
$D$2:$D$10,H$14,
$G$2:$G$10,"="&"",
$F$2:$F$10,"="&"")
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
A very small simplification which should work the same . . .

You can replace
"="&""
with just
""

And you can replace
"< >"&""
with
"< >"
 
Upvote 0
Welcome to the forum.

In addition to Gerald's idea, you can remove the "<>" ranges and conditions because if the range is empty, it will contribute 0 to the total. So with those changes, your formula is:

=SUMIFS(
$G$2:$G$10,
$B$2:$B$10,$C15,
$C$2:$C$10,$C$13,
$D$2:$D$10,H$14)
+SUMIFS(
$F$2:$F$10,
$B$2:$B$10,$C15,
$C$2:$C$10,$C$13,
$D$2:$D$10,H$14,
$G$2:$G$10,"")
+SUMIFS(
$E$2:$E$10,
$B$2:$B$10,$C15,
$C$2:$C$10,$C$13,
$D$2:$D$10,H$14,
$G$2:$G$10,"",
$F$2:$F$10,"")

Next, if I read your formula correctly, you want to pick the rightmost value from the F:H columns that matches your conditions. I've tried several options, but this seems easiest. Add a helper column in H (you can put it elsewhere if you want) with this formula:

H2: =IFERROR(LOOKUP(2^999,E2:G2),0)

drag down the column. Then your SUMIFS would only be:

=SUMIFS($H$2:$H$10,$B$2:$B$10,$C15,$C$2:$C$10,$C$13,$D$2:$D$10,H$14)

Hope this helps.
 
Upvote 0
Column1
Column2Column3Column4Column5Column6
AAAAAA1009592
AAAAAA858381
AAABBB200199160
ABBAAA
655549
BAAAAA898883
B
AABBB150149145
B
BB
AAA
140135
BBBBBB190185
BAAAAA510
AA
AAABBB
A173160
B593145

<tbody>
</tbody>

Forumula is used in D15 with red font.
 
Upvote 0
Welcome to the forum.

In addition to Gerald's idea, you can remove the "<>" ranges and conditions because if the range is empty, it will contribute 0 to the total. So with those changes, your formula is:

=SUMIFS(
$G$2:$G$10,
$B$2:$B$10,$C15,
$C$2:$C$10,$C$13,
$D$2:$D$10,H$14)
+SUMIFS(
$F$2:$F$10,
$B$2:$B$10,$C15,
$C$2:$C$10,$C$13,
$D$2:$D$10,H$14,
$G$2:$G$10,"")
+SUMIFS(
$E$2:$E$10,
$B$2:$B$10,$C15,
$C$2:$C$10,$C$13,
$D$2:$D$10,H$14,
$G$2:$G$10,"",
$F$2:$F$10,"")

Next, if I read your formula correctly, you want to pick the rightmost value from the F:H columns that matches your conditions. I've tried several options, but this seems easiest. Add a helper column in H (you can put it elsewhere if you want) with this formula:

H2: =IFERROR(LOOKUP(2^999,E2:G2),0)

drag down the column. Then your SUMIFS would only be:

=SUMIFS($H$2:$H$10,$B$2:$B$10,$C15,$C$2:$C$10,$C$13,$D$2:$D$10,H$14)

Hope this helps.

Honestly, I am surprised that you understood my intention correctly without any reference data based which I was only able to post below later. However, detailed explanation is also posted below:

Basically i want the sum of "Column 6" for the given criteria but the data in Column 6 can only be entered after some delay w.r.t. Column 1, Column 2, Column 3 & Column 4.

Till Column 6 data is entered, i want excel to use the number available in Column 5 which is also entered after some delay w.r.t. Column 1, Column 2, Column 3 & Column 4 but before Column 6.
And till Column 5 data is entered, i want excel to use the number available in Column 4.
Now I am familiar with two SUM/IF arrangements as shown in first post.
First one is array sum/if arrangement which is convenient to write but results in terribly long calculation time with 1.5 seconds for just one column and I have over 100 columns in one sheet and about 9 sheets.
Second one is using SUMIFS which requires extensive time to write but relatively better calculation time of 0.5 seconds for column but is still quite high.
Now I need to do away with the array arrangement but doing so will take quite some time and I want to know if there is any better/other arrangement.
Just let me know other arrangement which can get the required result and I will check the arrangement for calculation timing. If the other arrangement is also convenient to write than that is a plus.


I will check the helper column arrangement for getting the correct result and calculation timing today. But as per my experience, SUMIFS can only check for criteria in one dimension. I mean if I use a helper column which will identify the column to be used for sum range, specifying a criteria with column range while other criteria are with row ranges is not possible with SUMIFS. Please correct me if I am wrong and how to do it as I faced such requirement in past but couldn't get SUMIFS to do it.
 
Upvote 0
Given your layout, here's how the helper column would look:


Book1
ABCDEFGH
1Column1Column2Column3Column4Column5Column6Helper Column
2AAAAAA100959292
3AAAAAA85838181
4AAABBB200199160160
5ABBAAA65554949
6BAAAAA89888383
7BAABBB150149145145
8BBBAAA140135135
9BBBBBB190185185
10BAAAAA510510
11
12
13AA
14AAABBB
15A173160
16B593145
Sheet1
Cell Formulas
RangeFormula
D15=SUMIFS($H$2:$H$10,$B$2:$B$10,$C15,$C$2:$C$10,$C$13,$D$2:$D$10,D$14)


True, SUMIFS only works in one dimension, but you can use other tricks to compress the second dimension into 1, which is what the helper column does. And you can possibly use other functions, such as SUMPRODUCT to work in multiple dimensions. For example, I noticed that the values in E:F:G are always decreasing. If that's always true, we can just pick the minimum value from that range. This formula works without a helper column:

D15: =SUMPRODUCT(--($B$2:$B$10=$C15),--($C$2:$C$10=$C$13),--($D$2:$D$10=D$14),SUBTOTAL(5,OFFSET($E$2:$G$2,ROW($E$2:$E$10)-ROW($E$2),0)))

However, I suspect it may be slower than the helper column method. And of course, if the strictly decreasing rule isn't true, then it won't work right.

Let us know how your timing tests work, and if there's anything else about your data that might provide a way to improve on these ideas.
 
Upvote 0
Given your layout, here's how the helper column would look:

ABCDEFGH
1Column1Column2Column3Column4
Column5Column6Helper Column
2AAAAAA100959292
3AAAAAA85838181
4AAABBB200199160160
5ABBAAA65554949
6BAAAAA89888383
7BAABBB150149145145
8BBBAAA140135135
9BBBBBB190185185
10BAAAAA510510
11
12
13AA
14AAABBB
15A173160
16B593145

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
D15=SUMIFS($H$2:$H$10,$B$2:$B$10,$C15,$C$2:$C$10,$C$13,$D$2:$D$10,D$14)

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

<tbody>
</tbody>



True, SUMIFS only works in one dimension, but you can use other tricks to compress the second dimension into 1, which is what the helper column does. And you can possibly use other functions, such as SUMPRODUCT to work in multiple dimensions. For example, I noticed that the values in E:F:G are always decreasing. If that's always true, we can just pick the minimum value from that range. This formula works without a helper column:

D15: =SUMPRODUCT(--($B$2:$B$10=$C15),--($C$2:$C$10=$C$13),--($D$2:$D$10=D$14),SUBTOTAL(5,OFFSET($E$2:$G$2,ROW($E$2:$E$10)-ROW($E$2),0)))

However, I suspect it may be slower than the helper column method. And of course, if the strictly decreasing rule isn't true, then it won't work right.

Let us know how your timing tests work, and if there's anything else about your data that might provide a way to improve on these ideas.

Strictly decreasing rule isn't true for my actual data and the relevant data columns of criteria ranges and sum ranges are not adjacent at all.

So I used the helper column with IF statement. For sample data I shared, helper column formula in H2 is

=IF(G2<>"",G2,IF(F2<>"",F2,E2))

The calculation time for SUMIFS with helper column arrangement was average 0.14 seconds (0.12 seconds for SUMIFS formula column and 0.02 seconds for Helper column) in comparison to average 1.5 seconds for the array sum/if formula and average 0.5 seconds for SUMIFS formula I mentioned in my original post for the same column's calculation.

This is a big improvement and seems it can be bettered. Although adding helper columns for my data would be cumbersome but it will be a one time activity.

Thanks Eric for your expert advice and quick response.
 
Upvote 0
Maybe a pivottable with the helper column would further improve performance?

Good idea. The reason i didn't use pivot table earlier was that it would not sum the most right number. Now with helper column it seems the right thing to do. Although I face some problems while referencing to pivot table cells in drag formulas but i guess its time to get into that as well.
 
Upvote 0

Forum statistics

Threads
1,214,947
Messages
6,122,411
Members
449,081
Latest member
JAMES KECULAH

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