Sub topic 4
Returning Text, Numbers, or Nothing
Assume you already know how to enter data in Google Sheets, use cell references such as A1, and write basic arithmetic formulas. In this chapter, you will choose what an IF formula returns when its test is true or false.
An IF formula has three parts:
=IF(test, value_if_true, value_if_false)The test produces either TRUE or FALSE. Google Sheets then returns the second argument when the test is TRUE. It returns the third argument when the test is FALSE.
For example, suppose B2 contains a student's score:
=IF(B2>=50, "Pass", "Fail")If B2 contains 72, the result is the text Pass. If B2 contains 35, the result is Fail.
Returning text
Text results must be enclosed in quotation marks. Quotation marks tell Google Sheets that the words are literal text, not cell references or function names.
=IF(A2="Paid", "Done", "Follow up")This formula checks whether A2 contains Paid. If it does, the result is Done. Otherwise, the result is Follow up.
Text comparison with the equals operator is not case-sensitive. Therefore, Paid, paid, and PAID match the condition. Extra spaces do matter. A cell containing Paid followed by a space may not match as expected.
You can return text that describes a calculation or status:
=IF(C2>=TODAY(), "Current", "Expired")Here, the result is text, while the test compares a date in C2 with the current date.
Returning numbers
Numbers do not need quotation marks. Leaving them unquoted keeps them numeric, so you can use the result in later calculations.
=IF(B2>=50, 10, 0)This returns 10 for a passing score and 0 for a failing score. For example, you could sum the result column to count or total awards.
Compare these formulas:
=IF(B2>=50, 10, 0)=IF(B2>=50, "10", "0")The first formula returns numbers. The second returns text that looks like numbers. Text may not behave correctly in arithmetic, sorting, or charts. Use quotation marks only when the result should be text.
Returning nothing
To make a result cell appear empty, return an empty string: two quotation marks with nothing between them.
=IF(A2="", "", IF(B2>=50, "Pass", "Fail"))This formula first checks whether A2 is empty. If it is, the formula returns an empty string. Otherwise, it checks the score in B2.
An empty string is not exactly the same as a truly empty cell. The formula still exists in the cell, and some functions may treat the result differently from a cell that has never contained anything. However, it is useful for keeping unfinished rows visually clean.
You can also omit the false-value argument:
=IF(B2>=50, "Pass")When B2 is below 50, Google Sheets returns FALSE. This is different from returning an empty string, so use this shorter form only when FALSE is acceptable.
How the three outputs work
Choosing the right result
| Need | Example return value | Result type |
|---|---|---|
| Display a status | "Pass" | Text |
| Add or average the result later | 1 or 0 | Number |
| Hide unfinished rows | "" | Empty string |
Keep both possible outputs compatible with their purpose. Returning Pass in one branch and 0 in the other can be valid, but it creates a mixed text-and-number column that may be harder to analyze.
Exercise
Write a formula that returns 5 when C2 is at least 80, returns 2 when C2 is at least 50, and returns 0 otherwise.
Show answer
=IF(C2>=80, 5, IF(C2>=50, 2, 0))