Why does my nested IF return the wrong result?
Formula (Excel and Google Sheets)
=IF(B2>20,"Freight",IF(B2>5,"Large",IF(B2>1,"Standard","Letter")))The tests are in the wrong order: IF stops at the first TRUE. With > tests, check the largest threshold first: =IF(B2>20,"Freight",IF(B2>5,"Large",IF(B2>1,"Standard","Letter"))).
- Result on the example
- one result per row in
C2, filled down toC7 - Works in
- Every current version
- Google Sheets
- Same formula
See it work
The formula is already in C2, filled down to C7. Change any input and the result updates, or edit the formula to experiment.
How it works
IF stops at the first test that is TRUE. Testing B2>1 first catches every parcel over 1 lb, so a 27.5 lb parcel never reaches the Freight test and is labeled Standard. Checking the largest threshold first sends each parcel to the narrowest band it fits.
=IF(B2>20,"Freight",IF(B2>5,"Large",IF(B2>1,"Standard","Letter")))Result"Letter"
B20.6The value in B2.
B2>20FALSEThe > operator tests greater than.
B2>5FALSEThe > operator tests greater than.
B2>1FALSEThe > operator tests greater than.
IF(B2>1,"Standard","Letter")"Letter"IF: Returns one value if a test is true, another if false.- logical_test
B2>1FALSE - value_if_true
"Standard"not used - value_if_false
"Letter"
- logical_test
IF(B2>5,"Large",IF(B2>1,"Standard","Letter"))"Letter"IF: Returns one value if a test is true, another if false.- logical_test
B2>5FALSE - value_if_true
"Large"not used - value_if_false
IF(B2>1,"Standard","Letter")"Letter"
- logical_test
IF(B2>20,"Freight",IF(B2>5,"Large",IF(B2>1,"Standard","Letter")))"Letter"IF: Returns one value if a test is true, another if false.- logical_test
B2>20FALSE - value_if_true
"Freight"not used - value_if_false
IF(B2>5,"Large",IF(B2>1,"Standard","Letter"))"Letter"
- logical_test
In Google Sheets
The same formula works in Google Sheets: =IF(B2>20,"Freight",IF(B2>5,"Large",IF(B2>1,"Standard","Letter"))). 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 |
|---|---|---|
| =IFS(B2>20,"Freight",B2>5,"Large",B2>1,"Standard",TRUE,"Letter") | Letter, Standard, Large… | The same order in IFS, which is easier to read. |
| =IF(B2<=1,"Letter",IF(B2<=5,"Standard",IF(B2<=20,"Large","Freight"))) | Letter, Standard, Large… | Working up from the smallest band with <= is just as valid. What matters is checking the bands in order. |
Common mistakes
- With > tests start from the biggest threshold; with < or <= tests start from the smallest.
- Boundary values go to the lower band with >: a 5 lb parcel is Standard. Use >= if it should move up.
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.
Why does my nested IF return the wrong result
C2, pick the service: Freight over 20 lb, Large over 5 lb, Standard over 1 lb, otherwise Letter. Fill down to C7.Questions
How do I test a nested IF?
Try one value inside each band and one on each boundary, such as 1, 5 and 20 here.
When should I switch to a lookup table?
Once there are more than three or four bands, or they change often. List the band starts in cells and use XLOOKUP(B2,starts,labels,,-1).
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.