Excel IF Function for Beginners: Turn a Rule into a Formula

Excel TutorialsBy QueryFun4 min read
On this page
  1. Set up a stock example
  2. Understand the three arguments
  3. Test one TRUE case and one FALSE case
  4. Keep missing inputs visible
  5. Calculate a quantity with the same rule
  6. Avoid hiding errors too early
  7. Try it yourself

The Excel IF function chooses between two results based on a condition. It can help label a task, flag a low stock item or check whether a target has been reached. The most important step is writing the rule clearly before turning it into a formula.

Before you start: Use a new practice workbook. The names and figures below are fictional. Enter the headers in row 1 and the first record in row 2 unless a step says otherwise. Formulas use English function names and commas; your regional settings may require semicolons instead. Save a copy before experimenting.

Set up a stock example

Enter this table in A1:C5. Stock is the quantity available. Reorder level is the threshold the shop uses for deciding when to order more.

ProductStockReorder level
Notebook810
Pen2520
Folder1010
Marker05

In D1 type Status. Our rule is “Reorder when stock is less than or equal to the reorder level.” That includes the exact threshold. If the business wanted to reorder only below the level, the comparison would change.

Understand the three arguments

In D2 enter =IF(B2<=C2,"Reorder","OK") and press Enter. IF takes a logical test, a result for TRUE, and a result for FALSE. B2<=C2 is the test. The quoted words are the two possible text outputs.

Copy the formula into D3:D5. The statuses should be Reorder, OK, Reorder and Reorder. Folder is the important boundary test because its stock equals its reorder level. Using < instead of <= would label it OK and implement a different rule.

Text results need double quotes. Cell references and numeric outputs do not. =IF(B2<=C2,1,0) returns numeric flags that you could later add, while =IF(B2<=C2,"1","0") returns text that looks like numbers.

Test one TRUE case and one FALSE case

Change Notebook stock in B2 to 12. Its status should become OK. Change it back to 8. Testing both branches helps reveal a reversed comparison or swapped result labels.

Then inspect D5's formula. It should refer to B5 and C5, not still to B2 and C2. Copying a formula is reliable only when its references represent the right row. This is why small test data is helpful before a formula is used across hundreds of records.

Keep missing inputs visible

A blank stock cell is not necessarily zero stock. In a numeric comparison, Excel can treat a blank as zero, which may trigger a reorder label even though no one entered a stock count. If missing stock is possible, use a deliberate first check.

=IF(B2="","Check stock",IF(B2<=C2,"Reorder","OK")) returns Check stock when the stock input is blank or evaluates to an empty string. Otherwise it applies the reorder rule. This is a nested IF: one IF sits inside another.

This version still assumes the reorder level is present and both numeric inputs are valid. You could also check C2, or use data validation to reduce invalid entries. A more complicated formula should be driven by a real input problem, not added just to look advanced.

Calculate a quantity with the same rule

Suppose the target stock level is 30 for every product. In E1 type Units to reach 30. In E2 use =IF(B2<30,30-B2,0) and fill down. You should get 22, 5, 20 and 30.

This is a separate rule from the reorder label. Even a product marked OK may need units to reach 30. Clear column headings prevent someone from mistaking a planning figure for an instruction to place an order immediately.

Avoid hiding errors too early

If a formula produces an error, inspect the inputs and references before wrapping everything in IFERROR. Returning an empty string for every error can make an incomplete sheet look complete. IF makes a choice based on a rule; it does not verify that the rule is sensible or that the inputs are accurate.

Try it yourself

Create a new three-row score list: Amina 49, Brian 50 and Chao 80. Label scores of 50 or more Pass, and scores below 50 Review. What should each label be, and which record checks the boundary?

Check your answer

If the names are in A2:A4 and scores in B2:B4, use =IF(B2>=50,"Pass","Review") in C2 and fill down. Amina is Review, Brian is Pass and Chao is Pass.

Brian's 50 checks the exact boundary. A formula using >50 would incorrectly classify that row under the stated rule. Test a blank score too if missing scores are possible, and decide whether a separate Missing label is needed.

Keep learning: Return to the Excel learning path to choose your next lesson.

Leave a Reply

Your email address will not be published. Required fields are marked *