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:

[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]0.75[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD][/TD]
[TD]0.25[/TD]
[TD]0.50[/TD]
[TD]0.75[/TD]
[TD]1.00[/TD]
[TD]2.00[/TD]
[TD]3.00[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD][/TD]
[TD]1.44[/TD]
[TD]1.46[/TD]
[TD]1.53[/TD]
[TD]1.68[/TD]
[TD]2.32[/TD]
[TD]3.01[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]50[/TD]
[TD]1.78[/TD]
[TD]1.80[/TD]
[TD]1.88[/TD]
[TD]1.92[/TD]
[TD]2.40[/TD]
[TD]3.22[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD][/TD]
[TD]0.48[/TD]
[TD]0.60[/TD]
[TD]0.70[/TD]
[TD]0.80[/TD]
[TD]0.90[/TD]
[TD]1.00[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]25[/TD]
[TD]1.23[/TD]
[TD]1.26[/TD]
[TD]1.35[/TD]
[TD]1.40[/TD]
[TD]1.88[/TD]
[TD]2.52[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD][/TD]
[TD]1.60[/TD]
[TD]1.70[/TD]
[TD]1.80[/TD]
[TD]1.90[/TD]
[TD]2.22[/TD]
[TD]3.33[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]10[/TD]
[TD]0.97[/TD]
[TD]1.02[/TD]
[TD]1.30[/TD]
[TD]1.55[/TD]
[TD]1.75[/TD]
[TD]1.99[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD][/TD]
[TD]1.41[/TD]
[TD]1.43[/TD]
[TD]1.66[/TD]
[TD]1.84[/TD]
[TD]1.98[/TD]
[TD]2.04[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]50[/TD]
[TD]1.22[/TD]
[TD]1.25[/TD]
[TD]1.63[/TD]
[TD]1.80[/TD]
[TD]2.21[/TD]
[TD]2.84[/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
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

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
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:

[Table="width:, class:grid"][tr][td="bgcolor:#C0C0C0"][/td][td="bgcolor:#C0C0C0"]
M​
[/td][td="bgcolor:#C0C0C0"]
N​
[/td][td="bgcolor:#C0C0C0"]
O​
[/td][td="bgcolor:#C0C0C0"]
P​
[/td][td="bgcolor:#C0C0C0"]
Q​
[/td][td="bgcolor:#C0C0C0"]
R​
[/td][td="bgcolor:#C0C0C0"]
S​
[/td][td="bgcolor:#C0C0C0"]
T​
[/td][/tr][tr][td="bgcolor:#C0C0C0"]
3​
[/td][td="bgcolor:#F3F3F3"]
Range
[/td][td="bgcolor:#F3F3F3"]
Formula
[/td][td="bgcolor:#F3F3F3"]
# Cells
[/td][td="bgcolor:#F3F3F3"]
Iterations
[/td][td="bgcolor:#F3F3F3"]
Total Calcs
[/td][td="bgcolor:#F3F3F3"]
Time
[/td][td="bgcolor:#F3F3F3"]
Time/Calc
[/td][td="bgcolor:#F3F3F3"]
Rel Speed
[/td][/tr]
[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]
[/table]
 
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,223,880
Messages
6,175,157
Members
452,615
Latest member
bogeys2birdies

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