Sum question

GAJITCS

Board Regular
Joined
Apr 21, 2015
Messages
66
Please excuse what will be a question with the most simple answer, but I'm suffering with Brain Fog today.

From the following collection of cells:

ABCDEFG
10.75
20.250.500.751.002.003.00
31.441.461.531.682.323.01
4501.781.801.881.922.403.22
50.480.600.700.800.901.00
6251.231.261.351.401.882.52
71.601.701.801.902.223.33
8100.971.021.301.551.751.99
91.411.431.661.841.982.04
10501.221.251.631.802.212.84
11

<tbody>
</tbody>
What I need to achieve in cell A11, is to multiply the values in range A2:A10 by the values in another column where the cell value in A1 is a match to a value in range B2:G2

I'm sure I've done this before and that it's not difficult, I'm just having a problem today getting my head around the logic.

The answer in this case should be the equivalent of adding the sums of (A4*D4), (A6*D6), (A8*D8) and (A10*D10) = 222.25

Many thanks. Hoping the fog will clear by morning.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Re: Sum question - Brain Fog

Try

=SUMPRODUCT(A2:A10,INDEX(B2:G10,0,MATCH(A1,B2:G2,0)))

M.
 
Upvote 0
Re: Sum question - Brain Fog

It doesn't matter because of the small size of the data, but that's way slower than Marcelo's formula, Eric:

M​
N​
O​
P​
Q​
R​
S​
T​
3​
Range
Formula
# Cells
Iterations
Total Calcs
Time
[td="bgcolor:#F3F3F3"]
Time/Calc
[/td][td="bgcolor:#F3F3F3"]
Rel Speed
[/td]

[tr][td="bgcolor:#C0C0C0"]
4​
[/td][td]I2:I101[/td][td] =SUMPRODUCT(A2:A10,INDEX(B2:G10,0,MATCH(A1,B2:G2,0)))[/td][td]
100​
[/td][td]
16,384​
[/td][td]
1,638,400​
[/td][td]
2.188​
[/td][td="bgcolor:#E5E5E5"]
0.000 001 335​
[/td][td="bgcolor:#E5E5E5"]
4.3​
[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
5​
[/td][td]K2:K101[/td][td] =SUMPRODUCT(A2:A10*B2:G10*(B2:G2=A1))[/td][td]
100​
[/td][td]
4,096​
[/td][td]
409,600​
[/td][td]
2.359​
[/td][td="bgcolor:#E5E5E5"]
0.000 005 760​
[/td][td="bgcolor:#E5E5E5"]
1.0​
[/td][/tr]
 
Last edited:
Upvote 0
Re: Sum question - Brain Fog

I suspected it would be. Marcelo's formula essentially performs a sequential search on a 1X6 array, then performs 9 multiplications and a sum. Mine performs 6*9*6=324 multiplications and a sum. I'm a bit surprised that the difference is only a factor of 4.3. But as you said, on a small range the actual time difference is negligible, and perhaps the shorter formula might be preferable for clarity.

In any case, thanks for calculating the timing. This gives the OP more information with which to choose a formula that best suits him/her.
 
Upvote 0
Re: Sum question - Brain Fog

In addition to the performance I think it's important that people learn to use the INDEX function in all its functionality. It is fast and flexible and few are aware of the ability to return an array of values using row_num = 0 to return all rows or col_num = 0 to return all columns.

M.
 
Upvote 0
Re: Sum question - Brain Fog

In addition to the performance I think it's important that people learn to use the INDEX function in all its functionality. It is fast and flexible and few are aware of the ability to return an array of values using row_num = 0 to return all rows or col_num = 0 to return all columns.

M.

Eric, of course this comment is not addressed to you :)

M.
 
Upvote 0
Re: Sum question - Brain Fog

Eric, of course this comment is not addressed to you :)

M.
No worries! :) I agree, the ability of INDEX to return an array is one of its coolest, most valuable, and unknown properties. I was working on a very similar formula to yours, but you beat me to it, so I decided to highlight a different way to use SUMPRODUCT. But as you and shg both pointed out, the choice of which formula is "best" depends on a lot of factors, some of which are not very obvious.
 
Upvote 0
Re: Sum question - Brain Fog

I thought I had replied to this yesterday, but can't see my post now.

Thank you everyone for your help. Both solutions worked.

I did ask about the formula timer, so thank you also Shg for posting the link.
 
Upvote 0

Forum statistics

Threads
1,216,082
Messages
6,128,702
Members
449,464
Latest member
againofsoul

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