Return 0 when a value of a cell is negative
I have a google spreadsheet that uses this function:
=SUM开发者_JS百科(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.
=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
IF((SUM(E:E) - SUM(C:C))< 0,0,SUM(E:E) - SUM(C:C))
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
.
I took another route - I just copied the entire column to another column to the far right, and then referenced that column for my formulas in the column I want to edit.
When you're finished, "hide" the copied column (click on the column menu and there is a "hide" option), but DO NOT delete it, because then your formulas will not work.
精彩评论