Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel formula to find sum of difference

I have excel sheet with 2 columns: baseline, current.
the baseline if base prices and the current is real price.
for example:

base | curr
-----|-----
10   | 15
8    | 8
9    | 5
1    | 2
-----|-----
27   | 28

Now, I need the difference if HIGHER current prices.. in our example, the first and last line have bigger current price, so i need the formula to return 6 (=15-10+2-1).

is there any way to do it in excel formula? I need to loop on all the rows and mark the curr>base rows, and then do the sum(curr-base) for everyone of the results.

I tried it with sumproduct, and other functions (sumifs and such) with no help...

any idea how to solve this?

Thanks!

like image 647
gabi Avatar asked Dec 31 '14 08:12

gabi


People also ask

How do I find the difference between two columns in Excel?

Navigate to the "Home" option and select duplicate values in the toolbar. Next, navigate to Conditional Formatting in Excel Option. A new window will appear on the screen with options to select "Duplicate" and "Unique" values. You can compare the two columns with matching values or unique values.


2 Answers

If you don't like those -- you can also get the formula this way:

=SUMPRODUCT((B1:B3>A1:A3)*(B1:B3-A1:A3))

Note: the * replaced the ,

like image 183
iDevlop Avatar answered Oct 04 '22 22:10

iDevlop


Found the answer.. no need for new column or so..

=SUMPRODUCT(--(B1:B3>A1:A3),--(B1:B3-A1:A3))

column base = A, curr = B

Thanks for trying..

like image 22
gabi Avatar answered Oct 04 '22 20:10

gabi