← All how-to recipes

How to use the IF function

✓ Verified in LibreOffice 25.8.7.3 ✓ Verified in Google Sheets (2026-08-30)

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

The formula

AppFormulaNotes
Excel (desktop)=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. We then ran the same formulas in Google Sheets, executed 2026-08-30: a formula-only workbook goes into Google Drive, which converts it to a Sheet and recalculates every formula with Google’s own engine, and comes back out as .xlsx carrying the values Google computed. It returned Pass for the worked example, the same value LibreOffice produced. Both engines’ numbers on this page are executed results. The Excel formula follows Microsoft’s official documented syntax — we do not run desktop Excel.

Functions used

IF — see full Excel, Google Sheets & LibreOffice compatibility for each.

Related recipes

Related comparisons