Excel sum only single or first duplicated value in a list - excel

I've a formula in Excel which I've found on the net which gives the required result but I don't fully understand how it works. This is =SUMPRODUCT(B1:B9/COUNTIF(A1:A9,A1:A9)) and the result is 129 for the following data (it adds single occurrences in Column B of the data, this being 13 + 24 + 92 = 129 which is the required result).
Row A B
1 1 13
2 1 13
3 1 13
4 1 13
5 3 24
6 3 24
7 3 24
8 12 92
9 12 92
I understand the COUNTIF(A1:A9,A1:A9) is creating an array {4;4;4;4;3;3;3;2;2) but I don't know how the range B1:B9 numerator is working to create the result. If the numerator was say the number "1" (i.e. the formula being instead =SUMPRODUCT(1/COUNTIF(A1:A9,A1:A9)), the result is 3 and I think is worked out as the sum of 1/4 + 1/4 + 1/4 + 1/4 + 1/3 + 1/3 + 1/3 + 1/2 + 1/2. So how when the B1:B9 is in the formula how step by step is it working it out?

You are pretty close to the answer yourself. Given your example you have two arrays:
The first one is the numbers from column B and the other one from the countif in column A:
{13;13;13;13;24;24;24;92;92} and {4;4;4;4;3;3;3;2;2}
In the sumproduct formula you have the division and therefore you get the arrays divided:
{13/4; 13/4; 13/4; 13/4; 24/3; 24/3; 24/3; 92/2; 92/2} and the sum of these numbers are:
3,25 + 3,25 + 3,25 + 3,25 + 8 + 8 + 8 + 46 + 46 = 129
And there is the magic number :-)

Related

Excel MERGE two tables

I have SET 1
CLASS
Student
TEST
SCORE
A
1
1
46
A
1
2
50
A
1
3
45
A
2
1
45
A
2
2
47
A
2
3
31
A
3
1
34
A
3
2
45
B
1
1
36
B
2
1
31
B
2
2
41
B
3
1
50
C
1
1
42
C
3
1
31
and SET 2
CLASS
SIZE
YEARS
A
39
7
B
20
12
C
31
6
and wish to COMBINE to make SET 3
CLASS
STUDENT
TEST
SCORE
SIZE
YEARS
A
1
1
46
39
7
A
1
2
50
39
7
A
1
3
45
39
7
A
2
1
45
39
7
A
2
2
47
39
7
A
2
3
31
39
7
A
3
1
34
39
7
A
3
2
45
39
7
B
1
1
36
20
12
B
2
1
31
20
12
B
2
2
41
20
12
B
3
1
50
20
12
C
1
1
42
31
6
C
3
1
31
31
6
so basically add the SIZE and YEARS columns from SET 2 and merge on CLASS onto SET 1. In excel how you can do this? I need to match on CLASS
Define both sets as tables and “left join” in PowerQuery. There you can choose the columns of the resulting table.
https://learn.microsoft.com/en-us/power-query/merge-queries-left-outer
If you have Set 1 on the top left of a worksheet "Set1" and Set 2 on the top left of a worksheet "Set2", then you can use the formula
=VLOOKUP(A2;'Set2'!$A$2:$C$4;2;FALSE), where $A$2:$C$4 is the range of Set2, and A2 is the class value from Set1, which is what is used to do the lookup in Set2. The next argument, 2, means to take the second row from Set2, and the FALSE at the end means that you only want exact matches on the CLASS. You can do auto-fill with this formula, and do similar steps for the years. If you look up the help for VLOOKUP within Excel, that should help you to understand how it works.
Your first set of data is essentially your primary set of data that you just want to add attribute columns to. I built this example on Google Sheets which should help explain. Using spill formulas, only a few cells are needed with their own formulas. You can see them as they are highlighted in yellow. When you use in Excel, obviously make sure you change the column references, but this would get you the answer.
Note you have to have SpillRange in Excel for this to work. To test, see if you have the formula =unique()
This solution may work for you if both sets start in the same column. As example in my image, both of them start at column A. You can get all data with a single VLOOKUP formula:
Formula in cell E2 is:
=VLOOKUP($A2;$A$22:$R$25;COLUMN($B22);FALSE)
Notice the mixed references at first and third argument and absolute references in the second one. Third argument is critical, because is the relational position between both sets, that's the reason it's easier if both sets start at same column. If not, you'll need to adjust this argument substracting or adding, depending on the case.
Anyways, with a single formula, you can get any number of columns. The only disavantage of this formula is that you need to manually drag to right until you got all the columns (10, 30 or whatever). You'll notice you are done because the formula will raise an error:
This error means you are trying to get a referenced outside of your column area.

Excel Multiply one set of values with given matrix and sum results

I need to redistribute values for Old entries by using new distribution in a given table.
Example:
Need to redistribute using given % in this table:
So New Value of Element 1 = 99% * old1 + 7% * old2 + 3% * old3 + 26% * old5
This is not whole table, it is pretty large. There must be a simpler way than adding things up manually.
You can use the MMULT() worksheet function for that.
Example:
A B C D E F
1 Amount
2 100
3 200
4 500
5 400
6
7 Percentages 1 2 3 4
8 99 7 3 26 =MMULT(B8:E8;A$2:A$5)/100
9 1 93 34 0 =MMULT(B9:E9;A$2:A$5)/100
10 0 0 63 74 =MMULT(B10:E10;A$2:A$5)/100
For your information: I've entered the first formula in F8, and dragged and dropped until F10.

EXCEL: Sum columns based on common index

I'm trying to sum columns that have a common index but the difficulty is that the index is not in the same row.
Here is an example
DayIndex2018 Value2018 DayIndex2017 Value 2017
empty empty 1 20
1 50 2 45
2 60 3 55
3 70 4 33
4 32 5 23
What I would like is to have the sum of "value 2017" for indexes that are in common with indexes for 2018: 20 + 45 + 55 + 33
I though of doing this with a sumif but rows need to be perfectly aligned.
Any idea of how I could do this?
Thanks
Use sumproduct to sum the array of sumif
Formula in cell F2:
=SUMPRODUCT(SUMIF(C2:C6,A2:A6,D2:D6))

Excel: why is the average of divisions different from division of sums?

So lets say I have two variables x and y. I calculate the total sum of each variable.
I calculate y/x for each row and also calculate y/x for the sum of both x and y columns (280/10=28).
I would expect this value (28) to be equal to the average of y/x (230/4=32.5), but it is different.
This might have a simple explanation, but I can't seem to find it.
Thanks in advance
This is really a mathematics question. The two are not equal:
10 200 30 40
─── + ──── + ─── + ───
10 + 200 + 30 + 40 1 2 3 4
────────────────── ≠ ────────────────────────
1 + 2 + 3 + 4 4
There really is no reason why they could be expected to be the same: when the second expression is rewritten with one common denominator, it becomes even more evident there is little it has in common with the first expression.
To get a common denominator, one finds the least common denominator, which in this case is 12, and so the second expression could be written as follows:
120 1200 120 120
──── + ──── + ──── + ────
12 12 12 12
──────────────────────────
4
Which is simplified to:
120 + 1200 + 120 + 120 5 + 50 + 5 + 5 65
────────────────────── = ────────────── = ── = 32.5
48 2 2
There clearly is no relation with the first expression.
What is equal?
10 + 200 + 30 + 40 AVG(10, 200, 30, 40)
────────────────── = ────────────────────
1 + 2 + 3 + 4 AVG(1, 2, 3, 4)
This works because you really divide both numerator and denominator with the same factor (4), which is a null-operation.

spoj - CPCRC1C, sum of digits of numbers 1 to n, need clarification, not solution

Once, one boy's teacher asked him to calculate the sum of numbers 1 through n.
the boy quickly answered, and his teacher made him another challenge. He asked him to calculate the sum of the digits of numbers 1 through n.
Input
Two space-separated integers 0 <= a <= b <= 109.
Output
The sum of the digits of numbers a through b.
Example
Input:
1 10
Output: 46
can someone explain what is meant by sum of the digits of numbers a to b?
from above, sum of {1 2 3 4 5 6 7 8 9 10 } is 55 , it is a well known Gaussian formula
but the output is 46!
if i count from 2 to 9, excluding the border numbers 1 and 10, the answer is 44 , still not 46
So what is meant by sum of digits of numbers?
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + (1 + 0)
Don't treat the 10 as the number 10, rather the digits 1 and 0

Resources