weighted sum

blue333

Board Regular
Joined
Mar 19, 2009
Messages
64
Hi

I need some help calculating a weighted sum. I have an example which shows how it should be done. Any help is great appreciated! Thanks in advance

Sample Data:
ABCDEFGTotal
B 48%5%33% 14%100%
C16%2%5%9%21%23%23%100%
F13% 35%30% 22%100%
H26% 39% 17%17% 100%
Z32% 4% 36%28%100%

<tbody>
</tbody><colgroup><col span="6"><col><col span="2"></colgroup>


AprilMayJuneJulyAugustSeptember
A652116609883
B951990432446
C14368761514
D47711565180
E525740654979
F238770631694
G47915963216
H22227072372
Z947320763359

<tbody>
</tbody><colgroup><col span="6"><col></colgroup>

Expected Outcome:
AprilMayJuneJulyAugustSeptember
B68.2945.8659.5235.1032.1450.10
C44.9863.9347.6357.7740.8162.47
F50.8764.5732.3043.3950.0064.00
H35.4831.7049.9167.6542.7457.22
Z44.1266.3647.4459.7645.0465.28

<tbody>
</tbody><colgroup><col><col><col span="4"><col></colgroup>

Sample Calculation:

68.29 = 0.48*95 + 0.05*14 + 0.33*47 + 0.14*47
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Maybe:


ABCDEFGHIJKLMNOPQRSTUVWXY
1ABCDEFGTotalAprilMayJuneJulyAugustSeptemberAprilMayJuneJulyAugustSeptember
2B48%5%33%14%100%A652116609883B68.3945.4459.8135.2432.0450.02
3C16%2%5%9%21%23%23%100%B951990432446C44.2563.1947.1857.4340.361.69
4F13%35%30%22%100%C14368761514F50.8464.732.3143.2649.9163.81
5H26%39%17%17%100%D47711565180H35.1131.1149.386742.3856.45
6Z32%4%36%28%100%E525740654979Z44.1266.3647.4459.7645.0465.28
7F238770631694
8G47915963216
9H22227072372
10Z947320763359
11

<tbody>
</tbody>
Sheet4

Worksheet Formulas
CellFormula
T2=MMULT(INDEX($B$2:$H$6,MATCH($S2,$A$2:$A$6,0),0)+0,OFFSET($L$2:$L$8,0,MATCH(T$1,$L$1:$Q$1,0)-1))

<tbody>
</tbody>

<tbody>
</tbody>

The numbers don't all match exactly, but they all seem to be in the ballpark. If you find one that's not right, let me know how it should be calculated.
 
Last edited:
Upvote 0
Sample Calculation:
68.29 = 0.48*95 + 0.05*14 + 0.33*47 + 0.14*47

Your sample calculation is incorrect. It should be:

Code:
0.48*95 = 45.60
0.05*14 =  0.70
0.33*47 = 15.51
0.14*47 =  6.58
          -----
          68.39, not 68.29

The difference might be (a) your calculation error, or (b) due to rounding of either the percentages or (unlikely) the integers.

In any case, that might explain the differences in the results that I get below, which are the same as EricW's results.

Sample Data:

A
B
C
D
E
F
G
H
I
1
A
B
C
D
E
F
G
Total
2
B
48%
5%
33%
14%
100%
3
C
16%
2%
5%
9%
21%
23%
23%
100%
4
F
13%
35%
30%
22%
100%
5
H
26%
39%
17%
17%
100%
6
Z
32%
4%
36%
28%
100%

<tbody>
</tbody>


A

B

C

D

E

F

G
8
April
May
June
July
August
September
9
A
65
21
16
60
98
83
10
B
95
19
90
43
24
46
11
C
14
3
68
76
15
14
12
D
47
71
15
6
51
80
13
E
52
57
40
65
49
79
14
F
23
87
70
63
16
94
15
G
47
91
59
63
21
6
16
H
22
22
70
72
3
72
17
Z
94
73
20
76
33
59

<tbody>
</tbody>

Expected Outcome:

A
B
C
D
E
F
G
19
April
May
June
July
August
September
20
B

68.39

45.44

59.81

35.24

32.04

50.02
21
C

44.25

63.19

47.18

57.43

40.30

61.69
22
F

50.84

64.70

32.31

43.26

49.91

63.81
23
H

35.11

31.11

49.38

67.00

42.38

56.45
24
Z

44.12

66.36

47.44

59.76

45.04

65.28

<tbody>
</tbody>


Formula:

B20: { =SUMPRODUCT(TRANSPOSE($B2:$H2), B$9:B$15) }

Copy B20 into B20:G24

Formulas displayed with curly brackets {...} are array-entered. Type the formulas without the curly brackets, then press ctrl+shift+Enter instead of just Enter. Excel displays the curly brackets in the Formula Bar to indicate that the formula is array-entered.
 
Last edited:
Upvote 0
joeu2004 is correct with his math. And looking at his formula, it occurs to me that I can simplify mine. I originally assumed that the headings on the side would not necessarily be in order, so I used MATCH to locate the proper row. But if they are always in order, you can simplify my formula to:

T2: =MMULT($B2:$H2+0,L$2:L$8+0)

Same results as post 2.
 
Upvote 0
Thank you both for your replies.

1. The sample calculation is "correct". I copied it from Excel but it had full decimal stored but only displayed the part without the decimal. When I copied it over to the forum it lost the decimals. I forgot to redo the expected results when the sample calculation was done. You guys are too sharp and noticed the mistake. Well done!

2. I got Eric's solution to work. I was going to try joeu2004 solution too until i realized something. This is perhaps due to the sample data I provided. No assumption should be made on the order of the letters in the columns or rows I have provided. It is a pure coincidence that they are "ABCDEFG". In practice, the letters are not guaranteed to be in any order. There could also be omissions (ie, ABDGJL).

Given this, how can the formulas be updated to actually search the letters? I have included revised examples with expected data. I cannot attach any files so I will expand the decimals to help get the expected results. If the results you get are close then that should be good enough.

Sample data:

ABCDZFGTotal
B47.61905%4.76190%33.33333%14.28571%100%
C16.27907%2.32558%4.65116%9.30233%20.93023%23.25581%23.25581%100%
F13.04348%34.78261%30.43478%21.73913%100%
H26.08696%39.13043%17.39130%17.39130%100%
Z32.00000%4.00000%36.00000%28.00000%100%

<tbody>
</tbody>


2018-042018-052018-062018-072018-082018-09
A652116609883
B951990432446
C14368761514
D47711565180
E525740654979
F238770631694
G47915963216
H22227072372
Z947320763359

<tbody>
</tbody>

expected outcome
2018-042018-052018-062018-072018-082018-09
B68.2945.8659.5235.1032.1450.10
C53.7767.2843.4460.0737.4758.28
F63.6569.4326.2246.7445.1357.91
H42.7834.4846.4369.5739.9653.74
Z44.1266.3647.4459.7645.0465.28

<tbody>
</tbody>

Thanks so much!!
 
Upvote 0
In that case, try:

Excel 2012
ABCDEFGHIJKLMNOPQRSTUVWXY
1ABCDZFGTotal2018-042018-052018-062018-072018-082018-092018-042018-052018-062018-072018-082018-09
2B47.62%4.76%33.33%14.29%100%A652116609883B68.28571245.8571459.5238135.0952332.1428550.09524
3C16.28%2.33%4.65%9.30%20.93%23.26%23.26%100%B951990432446C53.76743767.2790643.4418560.0697637.4651258.27907
4F13.04%34.78%30.43%21.74%100%C14368761514F63.65217369.4347826.2173946.7391345.1304457.91304
5H26.09%39.13%17.39%17.39%100%D47711565180H42.78260534.4782546.4347869.5652139.9565253.73913
6Z32.00%4.00%36.00%28.00%100%E525740654979Z44.1266.3647.4459.7645.0465.28
7F238770631694
8G47915963216
9H22227072372
10Z947320763359

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

Worksheet Formulas
CellFormula
T2=SUMPRODUCT(INDEX($B$2:$H$6,MATCH($S2,$A$2:$A$6,0),0),SUMIF($K$2:$K$10,$B$1:$H$1,L$2:L$10))

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

<tbody>
</tbody>



This assumes that the columns in tables 2 and 3 are in the same positions. If not, this version looks up the right column from table 2:

=SUMPRODUCT(INDEX($B$2:$H$6,MATCH($S2,$A$2:$A$6,0),0),SUMIF($K$2:$K$10,$B$1:$H$1,INDEX($L$2:$Q$10,0,MATCH(T$1,$L$1:$Q$1,0))))
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

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