Difference between sum of two columns is not equal? - excel

So I have two columns: A&B.
In one calculation I summed up each column then calculated the difference: SUM(A)- SUM(B) and got ~16M
In another calculation I found the difference between each line item and then summed that. So essentially SUM OF (A1-B1),(A2-B2),etc. Where I dragged the subtraction formula down to the end of the columns and just did the sum of that column. I got ~17M
Why are the not equal?

Related

Excel formula to calculate the sum of the first n% visible rows in a filtered column

As I stated in the title, I want to calculate the sum of the first n% rows in a filtered column. The total numbers of rows in the column varies due to the filtering options, so my formula must work with different values of n.
For example :
In column A, I have 10 rows that contain values from 10 to 1 ( I sorted them from largest to smallest ).
In column B, I have 10 corresponding rows that contain 2 names: 4 of them contain the value "Tom", six of them contain the value "Jerry". When I filter the whole table and select only the rows that contain the value "Jerry", I want to be able to calculate the sum of the first 20% of the corresponding 6 number values.
This could work without any filtering if you want.
With criteria for column B in E1 and percentage you looking for in F1 with the assumption we want to round up the percentage to integers.
So formula in D1:
=SUMPRODUCT(LARGE((B2:B11=E1)*(A2:A11),ROW(A1:INDEX($A:$A,ROUNDUP(COUNTIF(B2:B11,E1)*F1,0)))))
So, without your data, I came up with this, edit to suit your situation...
So, based on the comment, I did a second version:
The helper column in col C is used with sumproduct to give the result...
You can use the percentile function in AGGREGATE with SUMIFS to do what you want:
=SUMIFS(A:A,B:B,"Jerry",A:A,">="&AGGREGATE(16,7,A1:A10/(B1:B10="Jerry"),0.8))
If you want to use the filter to do the decision:
=SUMPRODUCT(SUBTOTAL(3,OFFSET(A1,ROW(A2:A10)-1,,1))*(A2:A10>=AGGREGATE(16,7,A2:A10,0.8)),A2:A10)

Dynamic SUM or SUMIF Formula

I want to get the SUM of the first column IF the next column has data. In this example, the second column has data for the first 6 rows, therefore the sum that I want to get is the sum of the first 6 numbers in column 1. How the second column gets its data is chronological, so there will be no skipped cells.
You could use this formula:
=SUMIFS(A:A,B:B,">0")
It will sum the numbers in the first column, if the corresponding letters in the second column are greater than zero. Let me know if this does not cover all of your criteria, I'm sure I can help.
Thanks.

Sum squares of the sum of two columns for any amount of rows

I am trying to calculate the sum of squares of the sum of two columns,
i.e.
C1 C2
a b
c d
Answer = (a+b)^2+(c+d)^2
I want this to all be in one equation and to generalise to any amount of rows, but it will always be just two columns.
Use SUMPRODUCT()
=SUMPRODUCT((A1:A3+B1:B3)^2)
To make the ranges dynamic use this:
=SUMPRODUCT(($A$1:INDEX(A:A,MATCH(1E+99,A:A))+$B$1:INDEX(B:B,MATCH(1E+99,A:A)))^2)
Now as the list grows or shrinks it will only look to the range with values.

SUMIF offsets SUMAREA by two rows

I'm using the sumif function in combination with index/match to sum up values from another table by row and column criteria. However, the area in which is summed up is always two rows lower than expected (see picture).
This is the formula:
=SUMIF($F:$F,$A4,INDEX($H$3:$J$3,0,MATCH(B$3,$H$3:$J$3,0)))
How would I fix this?
Found it myself, the matrix in the index should be over the whole column:
=SUMIF($F:$F,$A4,INDEX($H:$J,0,MATCH(B$3,$H$3:$J$3,0)))

Excel calculated values sum Discrepancy

I have found that using the SUM() function to add a column of calculated values provides a different result than using the SUM() function against raw values. The following screen shots show a 1cent discrepancy between the sum of two columns that appear identical, except one is a calculated column and the other is raw data entry:
Note sum on column c is 1 cent different than column d
See the sum formula in row 22 is a simple sum
This is because the calculated values are not rounded to the 2nd decimal, they are just shown that way. But some of numbers may show 9.98 but really be 9.978.
If you want to see what I mean increase the decimal shown in those cells to four or more places.
To avoid this you can wrap the formulas in the range with =ROUND(...,2), where he ... is your formula. This will round the results to two places and then the two sums will match.

Resources