← All how-to recipes

How to use the IF function

✓ Verified in LibreOffice 25.8.7.3

Return one thing when a condition is true and another when it's false — the foundation of spreadsheet logic.

The formula

AppFormulaNotes
Excel=IF(A2>=60,"Pass","Fail")IF(test, value if true, value if false). The values can be text, numbers, or other formulas.
Google Sheets=IF(A2>=60,"Pass","Fail")Identical.
LibreOffice Calc=IF(A2>=60,"Pass","Fail")Identical.

How it works

IF has three parts: a test that's either true or false (A2>=60), the result if it's true ("Pass"), and the result if it's false ("Fail"). Here 72 clears 60, so it returns "Pass". Text results go in quotes; numbers and formulas don't. The test can use any comparison (=, <>, >, <, >=, <=) and can combine conditions with AND/OR — =IF(AND(A2>=60,B2="done"),...). For more than two outcomes, either nest IFs or use IFS/SWITCH (see those recipes). A common tidy-up: =IF(A2="","",...) returns blank instead of an error or 0 while a row is still empty.

Verified, not just documented

We ran =IF(A2>=60,"Pass","Fail") in LibreOffice 25.8.7.3 (headless, with forced recalculation) and it returned Pass — exactly the expected result. Every formula here is confirmed by actually executing it.