No history yet

Logical Formulas

Making Decisions in Your Data

Spreadsheets are great for storing data, but their real power comes from making automatic decisions based on that data. Instead of manually checking rows and making judgments, you can teach Excel your rules. The primary tool for this is the IF function.

The IF function checks if a condition is true or false and then returns a value you specify for each outcome.

The structure, or syntax, is straightforward. It always has three parts, or arguments:

  1. logical_test: The condition you want to check (e.g., is the value in cell A2 greater than 50?).
  2. value_if_true: What to show if the condition is met.
  3. value_if_false: What to show if the condition is not met.

Let’s say you have a list of student scores. You want to quickly label anyone with a score above 50 as "Pass" and everyone else as "Fail".

=IF(A2>50, "Pass", "Fail")

In this formula, A2>50 is the logical test. If the number in cell A2 is greater than 50, the formula returns the text "Pass". If it isn't, the formula returns "Fail".

Combining Conditions

Sometimes, one condition isn't enough. You might need to check if multiple criteria are met. That's where the AND and OR functions come in. You use them inside the logical_test part of an IF statement.

The AND function checks if all of its conditions are true. If even one is false, the whole thing is false.

Imagine you only want to pass students who scored above 50 and have a "Complete" project status.

=IF(AND(A2>80, B2="Complete"), "Pass", "Fail")

This formula only returns "Pass" if the score in A2 is over 80 and the text in B2 is exactly "Complete". If either of those conditions is not met, the result is "Fail".

The OR function is more lenient. It checks if at least one of its conditions is true.

For example, an employee gets a bonus if they are in the "Sales" department or if their performance review score is above 4.

=IF(OR(C2="Sales", D2>4), "Bonus Eligible", "Not Eligible")

Here, an employee from any department with a score of 5 would get a bonus. A salesperson with a score of 3 would also get one. The only way they don't get a bonus is if they are not in sales and their score is 4 or less.

Handling Complex Scenarios

What if you have more than two possible outcomes? For instance, assigning letter grades (A, B, C, D, F) based on a score. You can handle this by nesting IF statements. This means putting an IF function inside the value_if_false part of another IF function.

Nested IFs create a chain of decisions. If the first condition is false, Excel moves on to check the next one, and so on.

Let's translate a standard grading scale into a nested IF formula. If a score in A2 is 90 or above, it's an "A". If not, check if it's 80 or above for a "B", and so on.

=IF(A2>=90, "A", IF(A2>=80, "B", IF(A2>=70, "C", IF(A2>=60, "D", "F"))))

This might look complex, but Excel just evaluates it one step at a time from left to right. Once it finds a condition that is true, it returns the corresponding value and stops.

Cleaning Up Your Data

Formulas can sometimes produce errors. A common one is #DIV/0!, which happens when you try to divide by zero, or #N/A when a lookup function can't find a value. These errors look unprofessional and can break other calculations that depend on them.

The IFERROR function provides a simple way to clean these up. It checks if a formula results in an error. If it does, IFERROR returns a value you choose; otherwise, it returns the formula's normal result.

Lesson image

Imagine you are calculating a sales commission rate with the formula =A2/B2, but sometimes cell B2 is zero or empty. To avoid the ugly #DIV/0! error, you can wrap your formula in IFERROR.

=IFERROR(A2/B2, 0)

Now, if B2 is zero, the formula will return 0 instead of an error. You could also have it return a blank cell ("") or a text message like "Invalid Data".

Visualizing Logic with Formatting

Logical formulas aren't just for producing values in cells. They can also control Conditional Formatting, allowing you to automatically change a cell's appearance (like its background color or font style) based on its value or the value of another cell.

To do this, you create a new formatting rule and choose the "Use a formula to determine which cells to format" option. The formula you enter must be a logical test that returns TRUE or FALSE.

For example, let's say you want to highlight any entire row where the project status in column C is "Overdue". You would select the data range you want to format (e.g., A2:E100), create a new rule, and use this formula:

=$C2="Overdue"

The dollar sign \$ before the C is important. It locks the column, so every cell in the selected range (from A to E) looks at the value in column C for its own row. When the formula is TRUE for a given row (i.e., C2, C3, C4, etc. contains "Overdue"), the formatting you chose, like a red fill, is applied to that entire row.

This makes it easy to spot critical information at a glance, turning your static spreadsheet into a dynamic dashboard.

Quiz Questions 1/5

What are the three required arguments for a standard IF function in a spreadsheet, in the correct order?

Quiz Questions 2/5

You want to label an inventory item (in cell B2) as "Reorder" if its quantity (in cell A2) is less than 10 OR its status is "Damaged". Otherwise, the label should be "OK". Which formula accomplishes this?

These logical tools are the building blocks for creating spreadsheets that don't just hold information, but actively analyze it.