BUS 120 · Spreadsheets and Business Data
Logical and Text Functions
Use IF, AND, OR and IFERROR to make decisions in a sheet, and text functions to clean up messy imported data.
Key takeaways
- A comparison such as B2>100 produces TRUE or FALSE, and every logical function is built on that answer.
- IF chooses between two results, and you can combine it with AND and OR to test several conditions.
- The order of tests in a nested IF matters, because the first test that is true wins.
- Text functions such as TRIM, LEFT, MID and PROPER turn messy imported data into consistent data.
- IFERROR can tidy a report, but it can also hide a real problem if you use it carelessly.
Marco runs a made-up dog grooming van. Every Friday he scrolls through his invoices, hunting for the ones that are late. He squints at dates. He misses two. One customer has owed him money since spring, and Marco only notices in autumn.
A spreadsheet can do that hunting for him. It can look at each invoice, ask a yes-or-no question and write the answer in the next column. It can also clean up the customer list, where one client appears as " smith, JO", another as "Smith, Jo" and a third with a stray space that makes the two look different to a computer.
Decisions and cleanup are the jobs of logical and text functions.
Questions with only two answers
A comparison asks whether something is so. The spreadsheet answers TRUE or FALSE. These are called logical values.
| Symbol | Meaning | Example |
|---|---|---|
| = | equal to | =B2=0 |
| <> | not equal to | =B2<>0 |
| > | greater than | =B2>100 |
| < | less than | =B2<100 |
| >= | at least | =B2>=100 |
| <= | at most | =B2<=100 |
Try typing =5>3 into a cell. It shows TRUE. That looks useless alone. It becomes useful when another function acts on the answer.
IF: the fork in the road
IF takes three arguments: a test, the result if the test is true and the result if it is false.
=IF(test, value_if_true, value_if_false) If Marco's invoice balance is in B2, then =IF(B2>0, "Open", "Paid") labels it. Text results go inside quotation marks. Numbers do not. A pair of quotes with nothing between them, "", leaves the cell looking empty.
AND, OR and NOT
Real decisions often depend on more than one thing.
- AND is TRUE only when every test is true: =AND(B2>0, C2>30).
- OR is TRUE when at least one test is true: =OR(C2>30, B2>500).
- NOT flips the answer: =NOT(B2=0).
You usually place these inside an IF. For example, =IF(AND(B2>0, C2>30), "Call", "") flags invoices that are both unpaid and more than 30 days late.
Nested IFs and IFS
Sometimes there are more than two outcomes. You can put another IF in the "false" slot. This is the nesting you saw in formulas and essential functions.
=IF(B2=0, "Paid", IF(C2>30, "Call today", IF(C2>0, "Send reminder", "Not due yet"))) The program works left to right and stops at the first true test. Order is therefore part of the logic. Newer versions of Excel also offer IFS, which lists test and result pairs without the stack of parentheses. To give it a catch-all, make the last test simply TRUE. Check that everyone who opens your file has a version that supports it.
A worked example: Marco's overdue list
Marco puts today's reporting date in cell B1: December 5, 2026. Typing it in a cell, instead of using the TODAY function, keeps last month's report from changing every time he opens it.
His invoice list starts in row 4. Column B holds the due date, column C the amount and column D the amount paid. All figures are invented.
| Row | Customer | Due date | Amount | Paid |
|---|---|---|---|---|
| 4 | Okafor | Oct 20 | 120 | 0 |
| 5 | Lind | Nov 25 | 90 | 40 |
| 6 | Patel | Dec 15 | 150 | 0 |
| 7 | Reyes | Nov 1 | 75 | 75 |
He adds three columns.
E4 Balance: =C4-D4
F4 Days late: =MAX(0, $B$1-B4)
G4 Action: =IF(E4=0,"Paid",IF(F4>30,"Call today",IF(F4>0,"Send reminder","Not due yet"))) Dates are stored as day counts, so subtracting them gives days. The MAX with zero stops a future due date from showing negative lateness.
Now work each row.
- Okafor: balance 120. From October 20 there are 11 days left in October, plus 30 in November, plus 5 in December: 46 days. More than 30, so "Call today."
- Lind: balance 90 - 40 = 50. From November 25 there are 5 days left in November plus 5 in December: 10 days. "Send reminder."
- Patel: balance 150. The due date is in the future, so days late is 0. "Not due yet."
- Reyes: balance 75 - 75 = 0. "Paid," whatever the date says.
Total unpaid is =SUM(E4:E7), which is 120 + 50 + 150 + 0 = 320. The amount already overdue is =SUMIFS(E4:E7, F4:F7, ">0"). Reyes is counted by that rule too, but her balance is zero, so the answer is 120 + 50 = 170.
The three open balances add to $320; $170 of it is already overdue. Hypothetical example: the numbers are made up to show the method, not a quote or an average.
Lists like this are the start of an aging report, which accountants use when they estimate bad debts.
Reading the list like a manager
The action column is useful because it turns numbers into a to-do list. Marco does not need to compare dates in his head any more. He filters for "Call today," picks up the phone and works down the rows.
Notice how the logic is split across three columns. Balance answers "how much?" Days late answers "how long?" Action answers "what now?" He could cram all of it into one giant formula. He would regret it the first time something looked wrong, because he could not see which step failed.
He can also count each group with =COUNTIFS(G4:G7, "Call today"), which returns 1. If that number ever jumps to 9, something has changed in how customers pay, or in how quickly Marco sends invoices. Either way, he will see it on Friday instead of in autumn.
One more check is worth adding. What if a customer overpays? Reyes paid exactly 75. If she had paid 80, the balance would be -5. The test E4=0 would be false, and a negative balance would fall through to "Not due yet" or "Send reminder," depending on the date. Marco should add a first test for E4<0 with the result "Credit owed." Good logic asks about the odd cases, not only the usual ones.
The common mistake: tests in the wrong order
Marco's first attempt looked like this:
=IF(F4>0, "Send reminder", IF(F4>30, "Call today", "Not due yet")) Okafor is 46 days late. Is 46 greater than 0? Yes. So the formula says "Send reminder" and stops. The "Call today" test can never be reached, because anything over 30 is also over 0.
The fix is to test the strictest condition first. Whenever you build tiers, such as discounts or commission levels, go from the narrowest test to the widest. Then try your formula on values at the edges: 0, 1, 30 and 31. Edge values are where logic breaks.
Notice that 30 days exactly gives "Send reminder," since the test is "greater than 30." If the shop's policy says 30 days should trigger a call, use >=30. The policy decides, not the keyboard.
IFERROR: useful, and a little dangerous
IFERROR returns your chosen result when a formula produces an error. For example, =IFERROR(C4/D4, 0) shows 0 instead of #DIV/0! when D4 is zero.
The danger is that it catches every error, including a misspelled function name or a deleted cell. A broken formula then looks like a calm zero. A safer choice is to test for the exact problem: =IF(D4=0, "n/a", C4/D4). Other errors will still show up and ask for help.
When you build a long IF, write the rules in plain English first. "If nothing is owed, say Paid. Otherwise, if it is more than 30 days late, say Call today." Then translate one sentence at a time. If you cannot say the rule out loud, the formula will not save you.
Also consider putting the limit of 30 days in its own labeled cell. If Marco decides to call after 21 days, he edits one cell. The rule becomes visible to anyone who reads the sheet, and nobody has to dig through a formula to learn the shop's policy.
Cleaning up text
Data copied from banks, point-of-sale systems and old files is often untidy. Text functions fix it.
| Function | What it does | Example result |
|---|---|---|
| =TRIM(" Jo Smith ") | Removes extra spaces | Jo Smith |
| =PROPER("jo smith") | Capitalizes each word | Jo Smith |
| =UPPER("ab-12") | All capitals | AB-12 |
| =LEFT("INV-2045",3) | Characters from the left | INV |
| =RIGHT("INV-2045",4) | Characters from the right | 2045 |
| =MID("INV-2045",5,2) | Two characters from position 5 | 20 |
| =LEN("INV-2045") | Counts characters | 8 |
FIND tells you where one piece of text sits inside another. If A2 holds "Smith, Jo", then =FIND(",", A2) returns 6, because the comma is the sixth character. So =LEFT(A2, FIND(",",A2)-1) returns "Smith". And =TRIM(MID(A2, FIND(",",A2)+1, 100)) returns "Jo". Asking MID for 100 characters is fine, since it stops at the end of the text.
To join text, use the & symbol. =B2&" "&A2 puts a space between two cells.
Text functions return text, even when it looks like a number. The 2045 pulled out by RIGHT will be skipped by SUM. Wrap it in VALUE to turn it into a number: =VALUE(RIGHT(A2,4)).
PROPER is not perfect. It can mangle names such as McDonald or company initials. Review the results. Keep the original column too, so you can always go back.
Cleaning without destroying
Here is a safe routine for messy data. First, keep the imported columns exactly as they arrived. Second, add new columns beside them with your cleaning formulas. Third, check a sample of rows by eye, especially the longest, shortest and strangest entries. Fourth, count the rows before and after, so you know nothing vanished.
Suppose Marco imports 40 customer rows. After cleaning, he finds that several names now match each other. That is a clue, not proof. Two real people can share a name. Before he merges them, he compares phone numbers or addresses. A formula can suggest that two records are twins. A person should decide.
Excel also has built-in tools, such as Text to Columns and Flash Fill, that split or reshape text without formulas. They are quick for a one-time job. Formulas are better when the same messy file arrives every week, because the cleanup repeats itself when new data is pasted in.
For numbers that arrive with odd characters, SUBSTITUTE helps. It swaps one piece of text for another. =SUBSTITUTE("INV 2045", " ", "-") returns INV-2045. Replacing something with "" removes it altogether.
A quick test shows whether cleanup worked. =ISNUMBER(B2) returns TRUE only when B2 holds a real number. Its cousin =ISBLANK(B2) asks whether a cell is truly empty. A cell containing a single space is not blank, even though it looks that way.
Clean data pays off in the next lesson, lookup functions, where one stray space is enough to make a match fail.
Words to know
Comparison a test between two values that produces TRUE or FALSE.
Logical value either TRUE or FALSE.
IF function a function that returns one result when a test is true and another when it is false.
Nested IF an IF placed inside another IF to handle more than two outcomes.
Text string any run of letters, digits, spaces or symbols treated as words rather than as a number.
Aging report a list of unpaid invoices grouped by how long they have been overdue.
Check yourself
- What are the three arguments of IF, in order?
- If B2 is 0 and C2 is 45, what does =AND(B2>0, C2>30) return?
- A tier formula gives 10% off for orders of 500 or more and 5% off for orders of 200 or more. Which test should come first, and why?
- What does =MID("ACCT-7310", 6, 4) return?
- An invoice was due November 20 and the report date is December 5. How many days late is it?
- Why can IFERROR be risky?
Show the answers
- The test, the result when it is true and the result when it is false.
- It returns FALSE, because B2>0 is false even though C2>30 is true.
- Test 500 or more first, because every order of 500 or more also passes the 200 test and would stop there.
- It returns the text 7310, which is four characters starting at position 6.
- There are 10 days left in November plus 5 in December, so 15 days.
- It hides every kind of error, so a broken formula can look like a normal result.