Sum and subtract among column and row cells in excel - excel

I have an excel document where I have some amount in number in different cells. For example, I have number in column H,I,J of row 1.
How can I sum H+I and then subtract J from the result of H+I?
Thanks

Hi and welcome to Stack Overflow.
Let's say you have your original value in cell H1, the value to add in cell I1, and the value to subtract from their sum in cell J1.
The formula would be:
=H1+I1-J1
Notes:
Since addition and subtraction are related functions, there is no need to add parentheses to enforce proper order of operations.
Addition operator and subtraction operator signs work, no need for explicit Excel functions. There is no subtract function in Excel (perhaps where your confusion comes from), so if you wanted to use explicit functions you would write
=SUM(H1,I1,J1*-1)
If you're trying to sum over a larger range (entire columns of I and J, for example), let me know and I'll adapt my response.

If you want to add two columns say H1+I1 and subtract J1 from the result(H1+I1) and store the final result into column K1, then first select the K1 column and in the formula section type =H1+I1-J1. In the picture below, I am adding value of A1 and B1. After that subtracting the value of C1 from A1+B1. So, for the cell D1 to show the result of A1+B1-C1, select D1 and write the formula as it is showing in the picture.

Related

How to simplify the formula for sums with one variable in Excel

I need to sum the result of a formula, repeated several times, which has a single value that changes from 1 to 180.The final formula must be contained in a single cell.
Column A contains values ​​from 1 to 180 (to simplify in the example I have only put 13).
Cell B1 contains a value expressed as a percentage.
Column C (C1 to C13) contains the following formula (cell C1 in the example):
=+((1/(1+(A1*1/12*$B$1)))).
Cell C14 contains the sum of all results.
By defining X the variable value of column A, the formula is in practice the following:
Column A will be not present in my sheet, so therefore I cannot refer my formula to the contents of any cell.
My need is to have only two cells in my sheet: B1, with the rate value; and C1, with the sum of the products with X from 1 to 180. That is what is contained in cell C14.
Thanks for your help and for your patience with my bad English.
This can be done using SUMPRODUCT:
=SUMPRODUCT(1/(1+(A1:A13*1/12*$B$1)))
You can use the SEQUENCE() function for your problem to replace the column A in your example.
More specifically, you can write the formula:
=1/(1+SEQUENCE(180)/12*B1)
which will automatically create an array with a length of 180 cells returning your desired series of values.
If you don't want to 'print' out that series at all but only show the sum right away, simply enclose the formula with the SUM() function:
=SUM(1/(1+SEQUENCE(180)/12*B1))

Excel sheet dynamic summing condition based

Say I have the following numbers in cells in suceeding rows of column B 1,24,23,12,15,17. How do I get Excel to only add up to that cell so that the sum equals a predefined number (say 25) and return the corresponding row number at which this condition is satisfied?
In the example above, it should add B1 and B24 whose result equals the predefined number (25) and return row 2 as a result.
The challenge is unlike SUMIF and similar commands, I cannot prescribe a range B1:B6 or so. Instead of B6 it should be some number Bx where x (2 in this case) is decided on the fly. Does that make sense?
Thanks in advance.
You cannot do it with a single formula, but you can do it by adding a column with running totals. See this code example:

indirect reference for sum a range

I want to have a sum formula in a cell such as =SUM(Ex:Ey) while E is the column and x and y are row numbers. Is there a way I can have excel to match x and y to the numbers in other cells? For example: cell D1=3 and D2=12 and there are many numbers in column E. By the end of column E, I want to have a cell that sum only the rows from the numbers of D1 to D2, which is sum of E3 to E12 in this example. The idea is that I can change D1 and D2 to change what rows in column I want to sum.
You can use INDIRECT to reference a range using a constructed string address - SUM(INDIRECT("E"&D1&":E"&D2)).
"E"&D1&":E"&D2 will give you the string "E3:E12" in your example, which INDIRECT will then convert to a reference to that actual range.
Note that INDIRECT comes with a recalculation overhead, but will be fine if you aren't doing too many of them or too complex things!
Another way to achieve this is to use the sumif formula or sumifs for multiple conditions. This works better in some situations and can be easier to read and audit\review.

How does the SUMPRODUCT command works in this example?

The following code allows me to determine distinct values in a pivot table in Excel:
=SUMPRODUCT(($A$A:$A2=A2)*($B$2:$B2=B2))
See also: Simple Pivot Table to Count Unique Values
The code runs perfectly fine. However, can somebody help me understand how this code actually works?
You write: the following code allows me to determine distinct values in a pivot table in Excel
No. That formula alone does not do that. Read on for the explanation of what does.
There's a typo in the formula. It should be
=SUMPRODUCT(($A$2:$A2=A2)*($B$2:$B2=B2))
See the difference?
The formula starts in row 2 and is copied down. In each row, the $A$2 reference and the $B$2 reference will stay the same. The $ signs make them absolute references. The relative references $A2 and A2 will change their row numbers when copied down, so in row 3 the A2 will change to A3 and B2 will change to B3. In the next row it will be A4 and B4, and so on.
You may want to create a sample scenario with data similar to that in the thread you link to. Then use the "Evaluate Formula" tool on the Formulas ribbon to see step by step what is calculated. The formula evaluates from the inside out. Let's assume the formula has been copied down to row 5 and we are now looking at
=SUMPRODUCT(($A$2:$A5=A5)*($B$2:$B5=B5))
($A$2:$A5=A5) this bit compares all the cells from A2 to A5 with the value in A5. The result is an array of four values, either true or false. The next bit ($B$2:$B5=B5) also returns an array of true or false values.
These two arrays are multiplied and the result is an array of 1 or 0 values. Each array has the same number of values.
The first value of the first array will be multiplied with the first value of the second array. (see the red arrows)
The second value of the first array will be multiplied with the second value of the second array. (see the blue arrows)
and so on.
True * True will return 1, everything else will return 0. The result of the multiplication is:
The nature of the SumProduct function is to sum the result of the multiplications (the product), so that is what it does.
This function alone does not do anything at all to establish distinct values in Excel. In the thread you link to, the Sumproduct is wrapped in an IF statement and THAT is where the distinct values are identified.
=IF(SUMPRODUCT(($A$2:$A2=A2)*($B$2:$B2=B2))>1,0,1)
In plain words: If the combination of the value in column A of the current row and column B of the current row has already appeared above, return a zero, otherwise, return a 1.
This marks distinct values of the combined columns A and B.
Firts, i think you made a type here, as the formula should be :
=SUMPRODUCT(($A$2:$A2=A2)*($B$2:$B2=B2))
Let's decompose it in 2 parts:
First, we check the cells between A2 and A2, so only one cell, and we check the number of cells wich are equals to A2. In this case, the output should be 1, as you're comparing A2 with A2. However, you're not limited to compare A2 with A2. If you had chosen 2 cells equals to A2, the results would have been 2.You can compare as many cells as you want with A2 (replace the characters after the $ to modulate).
We do the same for the second bracket, except the pivot value is B2.
After that, you need to understand what the function SUMPRODUCT does. It sum the value of the product for a range of array. For example, say you have the value 1 on A1, 1 on A2, 2 on B1 and 3 on B2, if you make SUMPRODUCT((A1:A2)*(B1:B2)) , you will obtain (1*2) + (1*3) = 5. So, in the example you gave us, it will give the sum of (A2=A2)*(B2=B2) = 1.
So, it will output the number of pair (Ax,Bx) which is equals to (A2,B2). With the link, you can see that, if you select the first line only, the function will output 1 (and so the IF will output 1), but if you select the first 2 lines, the function will output 2, (and so the IF will output 0).
I hope this made sense to you, as i hoped i didn't make any mistakes along the explanation.

Excel SUMIF function sums multiple and/or wrong column.

I'm having an issue getting accurate data from the SUMIF function. This appears to be caused by the SKU and Product name being identical however I don't understand why the selected range would be ignored.
SUMIF(G:K,A2,K:K) - Cell D2 is calling for the sum of K yet returning the sum result of K2:M2. All other results in D are correct.
SUMIF(G:K,A2,I:I) - If I change the formula in D to SUM I:I (text not a numeric field) the function returns the sum of K:K
Example file http://tempsend.com/013C2B6378
According to the documentation here the range to be summed starts at the top left of the sum range (K:K in your first example) but its size is given by the size of the criteria range (G:K in your example). So I think that's why you're getting extra columns summed in your result.
If you have multiple criteria involving different columns, you should be able to use SUMIFS.
So let's say your data sit in 8 rows (including the headings).
then you simply need to change your formula to say, look for B2 in column G OR in I, if true, then sum the values in K. Right?
put this formula in B2 and press ctrl+shift+enter to calculate the formula.
=SUM(IF(($G$2:$G$8=B2)+($I$2:$I$8=B2),1,0)*$K$2:$K$8)
then drag and fill down until the last cell.
obviously you need to adjust the ranges in the formula to adapt to your own data.
tell me if you get to the answer via this.

Resources