Sub topic 4
Returning text, numbers, and calculations
This chapter assumes you can write a basic IF formula with a logical test, a value if true, and a value if false. It also assumes you can enter formulas and copy them down a column. Here you will see what the two result arguments can hold and how each kind of result behaves.
What an IF result can be
The second and third arguments of IF are not limited to one kind of value. Each can be text, a number, an empty string, a cell reference, or a full calculation. The two branches do not have to match in type, although mixing types has side effects that are covered below.
| Result type | Example argument | Notes |
|---|---|---|
| Text | `"Pass"` | Must be wrapped in double quotes |
| Number | `0` | No quotes, so Excel can still calculate with it |
| Empty string | `""` | Looks blank, but the cell is not truly empty |
| Cell reference | `B2` | Returns whatever B2 holds |
| Calculation | `B2*0.1` | Evaluated only when that branch is chosen |
Returning text
Text results are the most common. Any text must sit inside double quotes, or Excel reads it as a name and returns a #NAME? error.
=IF(B2>=60,"Pass","Fail")If the score in B2 is 60 or higher, the cell shows Pass. Otherwise it shows Fail. The quotes are not part of the result. They only mark where the text starts and ends.
Returning numbers and calculations
A result can be a calculation instead of a label. Excel works out only the branch the test selects.
=IF(B2>=1000,B2*0.1,0)When sales in B2 reach 1000, the formula returns 10% of B2. Otherwise it returns 0. Here the false branch is the plain number 0, written without quotes. This matters because a real number can be added up or averaged later, while the text "0" cannot.
flowchart TD
A["Test: B2 >= 1000"] -->|TRUE| B["Calculate B2 * 0.1"]
A -->|FALSE| C["Return 0"]The sketch above is for orientation only. The diagram below shows the same decision in the required form.
Returning an empty string
Sometimes you want the cell to show nothing for one outcome. Use two double quotes with nothing between them.
=IF(A2="","",B2*C2)When A2 is blank, the result is an empty string. Otherwise the formula multiplies B2 by C2. The cell looks empty, but it contains a formula that returned text of zero length.
=IF(C2=0,"",B2/C2)This version avoids a #DIV/0! error. If the divisor in C2 is zero, the cell stays visually blank instead of showing an error.
Mixed result types and their effects
You can return text from one branch and a number from the other. Excel allows it, but later formulas must handle both.
SUMandAVERAGEignore text results in a range, so an empty string is skipped safely.- The
+operator does not skip text. If a cell holds"", then=D2+1returns#VALUE!. COUNTcounts only numbers, whileCOUNTAcounts every non-empty cell, including cells that hold"".
Alignment as a clue
Excel aligns numbers to the right and text to the left by default. If a column of IF results is meant to be numeric but some values sit on the left, those values are text. A common cause is quoting a number, such as "0" in place of 0.
Choosing the right result
- Return text when the result is a label for a person to read, such as a status.
- Return numbers when later formulas will total, average, or compare the column.
- Return a calculation when the value depends on other cells. Put the arithmetic inside the IF so it is only worked out when needed.
- Return
""when a cell should look empty, and remember that it is still text.
Exercise
Sales are in B2. You want a formula that returns a 10% bonus when B2 is at least 1000, and otherwise returns nothing visible. A colleague plans to total the bonus column with =D2+D3. Write the formula, then say what problem the colleague may meet and what you would change.
Show answer
Formula: =IF(B2>=1000,B2*0.1,""). The false branch returns an empty string, which is text. The addition =D2+D3 returns #VALUE! when either cell holds "". Fix it by returning 0 instead of "" in the false branch (and formatting zeros to hide them if needed), or by totaling with =SUM(D2:D3), which ignores text.
Exercise
A column of IF results shows some numbers on the left side of their cells, and AVERAGE gives an unexpected result. What is the likely cause?
Show answer
The formula returns numbers inside quotes, such as "50", so they are text. Remove the quotes so the branch returns a real number.