🤖 Logic & Lookup Functions
Make your spreadsheet think. Use IF to make decisions, COUNTIF and SUMIF to analyze conditionally, and VLOOKUP/XLOOKUP to find information across tables — the skills that turn spreadsheets into databases.
Open a new Google Sheet. You'll build two separate tables during this module — one for IF/COUNTIF/SUMIF practice, and one for VLOOKUP/XLOOKUP. Keep this page open alongside your spreadsheet and type each formula as you encounter it. Don't just read — do.
The IF function lets your spreadsheet choose between two outcomes based on a condition. It works exactly like plain English: "IF this is true, show this; otherwise show that."
| Comparison Operator | Meaning | Example |
|---|---|---|
> | Greater than | A1 > 70 |
< | Less than | A1 < 60 |
>= | Greater than or equal | A1 >= 90 |
= | Equal to | A1 = "Pass" |
<> | Not equal to | A1 <> "Fail" |
Worked Examples:
Nesting IF for letter grades:
This is called a nested IF — one IF inside another. It checks conditions from highest to lowest. However, for more than 3 conditions, use IFS instead (it's much cleaner).
IFS lets you check multiple conditions in sequence without nesting IF inside IF inside IF. Each pair of arguments is: (condition, result_if_true).
Much cleaner than four nested IFs. The TRUE at the end is a trick — since TRUE is always true, it catches everything that didn't match earlier conditions (like an "else" clause).
| A — Category | B — Product | C — Revenue |
|---|---|---|
| Electronics | Laptop | 1200 |
| Electronics | Tablet | 450 |
| Books | Python Handbook | 35 |
| Clothing | Jacket | 89 |
| Electronics | Headphones | 120 |
| Books | Statistics Guide | 45 |
| Clothing | Sneakers | 110 |
| Electronics | Phone Case | 25 |
COUNTIF — Count cells that meet a condition
The criteria must be in quotes if it's text or contains a comparison operator.
SUMIF — Sum cells that meet a condition
The three arguments are: (1) the column you're checking for the condition, (2) what condition to match, (3) the column you want to add up when the condition is met.
COUNTIFS and SUMIFS — Multiple conditions at once
Add an "S" to handle multiple criteria at once:
Create a new sheet tab. Put your main product table starting at A1, and a lookup area starting at E1:
Main table (A1:C6):
| A — Code | B — Product | C — Price |
|---|---|---|
| P001 | Laptop Stand | $29.99 |
| P002 | USB Hub | $15.50 |
| P003 | Webcam | $79.00 |
| P004 | Keyboard | $49.99 |
| P005 | Mouse Pad | $8.99 |
Lookup area (E1:F2):
| E — Look up code: | F — Result: |
|---|---|
| P003 | (formula goes here) |
VLOOKUP looks up a value in the first column of a table, then returns a value from another column in the same row. It's like saying: "Find P003 in my product list, and tell me the price."
| Argument | What it means | In our example |
|---|---|---|
lookup_value | What to search for | E2 (the code P003) |
table_array | The table to search | A:C (columns A through C) |
col_index_num | Which column to return (1=A, 2=B, 3=C) | 3 for Price (column C) |
FALSE | Exact match (always use FALSE for codes/IDs) | FALSE |
In cell F2, type:
Change E2 to "P001" and F2 automatically updates to show $29.99. That's the power of lookup functions.
Common VLOOKUP gotcha: VLOOKUP only searches the first column of the table array. Your lookup column must be on the left. If you need to look up by a column that isn't leftmost, use XLOOKUP instead.
XLOOKUP is newer, simpler, and more flexible than VLOOKUP. It can look left or right, and the syntax is cleaner.
| Feature | VLOOKUP | XLOOKUP |
|---|---|---|
| Lookup direction | Left-to-right only | Any direction |
| Column index | Must count manually | Specify the range directly |
| "Not found" handling | Requires IFERROR wrapper | Built-in 4th argument |
| Return multiple columns | One at a time | Can return a range |
| Availability | All versions | Excel 365, Google Sheets (2020+) |
Recommendation: Use XLOOKUP for new work. Use VLOOKUP when sharing with people who might have older Excel versions.
Part 1 — Grade Book with IF and IFS:
Use the 10-student grades dataset from Module 02 (or recreate it). Add a column E called "Letter Grade". In E2, write an IFS formula that assigns:
- A if average ≥ 90
- B if average ≥ 80
- C if average ≥ 70
- D if average ≥ 60
- F if below 60
Copy it down for all 10 students.
Part 2 — Summary stats with COUNTIF and SUMIF:
In a summary area, answer these questions with formulas:
- How many students got an "A"? (use COUNTIF on the Letter Grade column)
- How many students scored above 80 on the Midterm? (COUNTIF)
- What is the total Final score for students who got an "A"? (SUMIF)
Part 3 — VLOOKUP:
Create a small product table (5 products with Code, Name, Price). Then in a separate area, create a "lookup cell" where you type a product code and a VLOOKUP formula returns the price automatically.
TRUE, "F" as the final pair so students below 60 get an F.VLOOKUP is one of the most searched Excel functions on the internet — and it's also one of the most complained about. People struggle with the column index number (you have to count manually), the "lookup must be in first column" restriction, and cryptic #N/A errors. Microsoft surveyed Excel users and found VLOOKUP was both beloved and frustrating — a classic "love-hate" relationship.
That's why Microsoft introduced XLOOKUP in 2019 and why Google added it to Sheets in 2020. VLOOKUP isn't going away — there are billions of spreadsheets using it — but for new work, XLOOKUP is strictly better. Think of VLOOKUP as the legacy system and XLOOKUP as the upgrade.
IF(condition, true_result, false_result)— makes a binary decision in a cell.IFShandles multiple conditions cleanly — end withTRUE, "else_value".COUNTIF(range, criteria)— counts cells matching a condition.SUMIF(range, criteria, sum_range)— sums cells where another column matches a condition.VLOOKUP(value, table, col_num, FALSE)— finds a value in the first column of a table and returns another column from the same row.XLOOKUP(value, lookup_range, return_range)— more flexible modern lookup; preferred for new work.- Always use
FALSE(exact match) in VLOOKUP when looking up codes or IDs.