Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return 0 when a value of a cell is negative

I have a google spreadsheet that uses this function:

=SUM(E:E) - SUM(C:C)

It adds up all the values of column E and column C and them subtracts the difference. I would like to be able to return a 0 if the difference is negative.

like image 597
Robert Avatar asked May 22 '10 20:05

Robert


People also ask

Is there an if negative function in Excel?

The Excel SIGN function returns the sign of a number as +1, -1 or 0. If number is positive, SIGN returns 1. If number is negative, sign returns -1.

How do you write an IF THEN formula in Excel?

Use the IF function, one of the logical functions, to return one value if a condition is true and another value if it's false. For example: =IF(A2>B2,"Over Budget","OK") =IF(A2=B2,B4-A4,"")


3 Answers

=MAX(SUM(E:E) - SUM(C:C),0) 

The MAX function receives a list values eg. MAX(1, 2, 3, 4) would give 4 so if you give it 0 then it will return 0 since it's higher than the negative result

like image 134
Kirschstein Avatar answered Oct 25 '22 18:10

Kirschstein


IF((SUM(E:E) - SUM(C:C))< 0,0,SUM(E:E) - SUM(C:C))

like image 22
Femaref Avatar answered Oct 25 '22 18:10

Femaref


Possible without changing the existing formula but with formatting such as:

#.00;"0";0

This differs from a formula approach such as =MAX(SUM(E:E)-SUM(C:C),0) because adding a number to the output of that formula will give as a result the added number, where SUM(C:C) is greater than SUM(E:E). Adding the same addend to =SUM(E:E)-SUM(C:C) where SUM(C:C) is greater than SUM(E:E) will not give the addend as the result, except when the added is 0.

like image 26
pnuts Avatar answered Oct 25 '22 19:10

pnuts