How to return 0 if a number is negative in Excel
Formula (Excel and Google Sheets)
=MAX(0,B2-C2)Take the larger of 0 and the result: =MAX(0,B2-C2). Negative results become 0 and positive ones pass through.
- Result on the example
- one result per row in
D2, filled down toD6 - Works in
- Every current version
- Google Sheets
- Same formula
See it work
The formula is already in D2, filled down to D6. Change any input and the result updates, or edit the formula to experiment.
How it works
MAX returns the larger of its arguments. When the subtraction is negative, 0 is larger, so you get 0; otherwise the remaining amount wins. It is the shortest way to write "if negative, then zero" and needs the subtraction only once.
=MAX(0,B2-C2)Result2150
B2$12,000The value in B2.
C2$9,850The value in C2.
B2-C22150The - operator subtracts.
MAX(0,B2-C2)2150MAX: Largest number.- number1
0 - number2
B2-C22150
- number1
In Google Sheets
The same formula works in Google Sheets: =MAX(0,B2-C2). We ran it in Google Sheets mode on the same data and it returns the same results.
Other ways to do it
Each one was run on the same example sheet.
| Formula | Result | When to use it |
|---|---|---|
| =IF(B2-C2<0,0,B2-C2) | $2,150, $0, $0… | The IF version spells the rule out, at the cost of writing the subtraction twice. |
| =IF(C2>B2,"Over budget",B2-C2) | $2,150, Over budget, $0…Different result | Flags overspending instead of hiding it. Rebrand and Events show "Over budget". |
Common mistakes
- MIN(0,…) does the opposite: it keeps the negative numbers and turns the positive ones into 0.
- A number format that hides negatives only changes the display; totals still include them.
Try it yourself
Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.
Return 0 if a number is negative
D2, show the budget left (budget minus spent), but never less than 0. Fill down to D6.Questions
How do I keep a result between 0 and a maximum?
Nest MIN around MAX: =MIN(1000,MAX(0,B2-C2)) keeps it between 0 and 1,000.
How do I total only the positive differences?
=SUMPRODUCT((B2:B6>C2:C6)*(B2:B6-C2:C6)).
Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.