MSBA-175 · Lesson 5 of 12 · 23 min
Logical functions: IFS, SWITCH and nested formulas
▶ Video coming soon A video version of this lesson is on the way.
With the data clean and protected, the Monday sessions turned to formulas, the second-largest part of MO-211. The exam objective here is long and specific: **perform logical operations by using nested functions including IF(), IFS(), SWITCH(), SUMIF(), AVERAGEIF(), COUNTIF(), SUMIFS(), AVERAGEIFS(), COUNTIFS(), MAXIFS(), MINIFS(), AND(), OR(), NOT(), and LET()**. Dagny's test case was the pricing logic in the client quote sheet, which Rosalind had been calculating in her head for years.
IF and nesting
IF returns one value when a condition is TRUE and another when it is FALSE. Nesting means putting one function inside another, and the oldest form of nesting is IF inside IF. Rosalind's rule for the service charge was: 18 percent for events over 150 guests, 15 percent for 60 to 150 guests, and 12 percent for smaller events.
=IF(C5>150, 0.18, IF(C5>=60, 0.15, 0.12))Nested IFs are evaluated left to right, and the first TRUE test wins. That makes the order of the tests important: testing C5>=60 first would give every large event 15 percent. Excel allows up to 64 nested levels, but anything beyond three or four is hard to read and easy to break. That is why Microsoft added IFS and SWITCH.
IFS
IFS takes pairs of tests and results and returns the result for the first test that is TRUE. It removes the brackets of nesting but keeps the same left-to-right logic.
=IFS(C5>150, 0.18, C5>=60, 0.15, TRUE, 0.12)IFS has no built-in "otherwise" value. If no test is TRUE, it returns #N/A. The standard fix is to make the last test TRUE, which always passes. Forgetting this is one of the most common exam mistakes, and it shows up only for the rows that miss every condition, such as an event with no guest count entered yet.
SWITCH
SWITCH compares one expression against a list of values and returns the result for the first match. Unlike IFS, it does have an optional default as its last argument. It suits exact matches, such as codes, rather than ranges of numbers.
=SWITCH(E5, "GG", "Garden Gold", "HC", "Harbour Classic", "LP", "Lighthouse Premium", "Unknown package")
=SWITCH(WEEKDAY(D5), 7, 1.1, 1, 1.05, 1)The second example shows that the expression can be a formula. WEEKDAY returns 1 for Sunday and 7 for Saturday by default, so Saturday events get a 1.1 multiplier, Sunday events 1.05 and everything else 1. When SWITCH has no default and nothing matches, it returns #N/A, just like IFS.
| Function | Best for | If nothing matches |
|---|---|---|
| IF (nested) | Two outcomes, or a few with complex tests | Returns the last FALSE value |
| IFS | Several ordered conditions such as tiers | #N/A unless the last test is TRUE |
| SWITCH | Exact matches against one value | The default, or #N/A if none is given |
AND, OR and NOT
AND returns TRUE only when all its arguments are TRUE; OR returns TRUE when at least one is; NOT reverses TRUE and FALSE. On their own they return TRUE or FALSE, which is useful in conditional formatting and validation. Inside IF or IFS they build compound conditions.
=IF(AND(C5>=100, E5="LP"), "Assign second coordinator", "")
=IF(OR(WEEKDAY(D5)=7, MONTH(D5)=12), "Peak", "Standard")
=IF(NOT(H5="Paid"), G5-F5, 0)The third formula could also be written H5<>"Paid". NOT is clearer when it reverses a longer expression, such as NOT(ISBLANK(C5)) or NOT(AND(...)). A useful identity is that NOT(AND(a, b)) is the same as OR(NOT(a), NOT(b)), which can make a confusing rule easier to read.
Conditional aggregation: the IFS family
The second half of the objective is about summarizing data that meets conditions. The older functions SUMIF, COUNTIF and AVERAGEIF take one condition. The newer SUMIFS, COUNTIFS, AVERAGEIFS, MAXIFS and MINIFS take one or more condition pairs. Their argument order differs, which the exam likes to test.
| Function | Arguments | Note |
|---|---|---|
| SUMIF | range, criteria, [sum_range] | Sum range comes last and is optional |
| SUMIFS | sum_range, criteria_range1, criteria1, … | Sum range comes first |
| COUNTIF / COUNTIFS | criteria_range1, criteria1, … | No sum range |
| AVERAGEIF | range, criteria, [average_range] | Like SUMIF |
| AVERAGEIFS | average_range, criteria_range1, criteria1, … | Like SUMIFS |
| MAXIFS / MINIFS | max_range or min_range, criteria_range1, criteria1, … | Like SUMIFS |
Dagny built a summary sheet for Rosalind with one row per package. Using the Bookings table, every formula used structured references so it would keep working as the table grew.
=SUMIFS(Bookings[Fee], Bookings[Package], A3, Bookings[Status], "<>Cancelled")
=COUNTIFS(Bookings[Package], A3, Bookings[Event date], ">="&DATE(2027,1,1))
=AVERAGEIFS(Bookings[Guests], Bookings[Package], A3)
=MAXIFS(Bookings[Fee], Bookings[Package], A3, Bookings[Event type], "Wedding")
=MINIFS(Bookings[Event date], Bookings[Status], "Due later")Criteria are text strings. Comparison operators go inside the quotes, and when a criterion combines an operator with a cell or a function, it is joined with &, as in ">="&DATE(2027,1,1) or "<"&J2. Wildcards work in text criteria: an asterisk matches any number of characters, a question mark matches exactly one, and a tilde before either one treats it as a literal character. The criterion Garden followed by an asterisk matches every venue name that starts with Garden. MINIFS and MAXIFS return 0, not an error, when no rows match, which can look like a real value; wrap them in IF with COUNTIFS when that matters.
Worked problem
Revenue by quarter for one package
Rosalind wants Garden Gold revenue for April to June 2027, excluding cancelled bookings. The quarter start date is in J2 and the end date in K2. Write the formula.
Show solution
- Sum range first: Bookings[Fee].
- Package condition: Bookings[Package], "GG".
- Date conditions: Bookings[Event date], ">="&J2 and Bookings[Event date], "<="&K2.
- Status condition: Bookings[Status], "<>Cancelled".
Answer: =SUMIFS(Bookings[Fee],Bookings[Package],"GG",Bookings[Event date],">="&J2,Bookings[Event date],"<="&K2,Bookings[Status],"<>Cancelled"). The same column can appear twice to build a date range.
Nesting the families together
The exam objective says "nested functions", and the most realistic exam tasks combine these tools. One common pattern is a conditional aggregate inside IF to avoid a misleading result. Another is IFS whose tests use COUNTIFS to look at other rows.
=IF(COUNTIFS(Bookings[Package],A3)=0, "No bookings", AVERAGEIFS(Bookings[Guests],Bookings[Package],A3))
=IFS(COUNTIFS(Bookings[Client],B5)>=3, "Loyal", COUNTIFS(Bookings[Client],B5)=2, "Returning", TRUE, "New")Logical values as numbers
Every comparison in Excel returns a logical value, TRUE or FALSE, and in arithmetic TRUE behaves as 1 and FALSE as 0. That makes some formulas shorter than they look. Instead of =IF(C5>150, 50, 0) for a large-event setup charge, =(C5>150)*50 gives the same answer, because the comparison becomes 1 or 0 before the multiplication. Adding comparisons counts how many are true: =(C5>150)+(E5="LP")+(WEEKDAY(D5)=7) returns a number from 0 to 3 that Dagny used as a "complexity score" for staffing.
The same idea explains the double minus that appears in older workbooks, as in =SUMPRODUCT(--(Bookings[Package]="GG"), Bookings[Fee]). The first minus turns TRUE and FALSE into -1 and 0, and the second turns them back into 1 and 0, so they can be multiplied. In current Excel, SUMIFS does this job more clearly, but recognizing the pattern helps when you inherit a workbook. Note that functions such as SUM ignore logical values typed directly into cells; they count only when they come from a calculation inside the formula.
Handling errors in logical formulas
Logical formulas often feed on lookups or divisions that can fail. IFERROR returns a value you choose when its first argument results in any error; IFNA does the same only for #N/A, which is the error lookups produce when nothing is found. Using IFNA rather than IFERROR around a lookup is better practice, because a #REF! or #VALUE! from a broken formula still shows up instead of being hidden.
=IFERROR(G5/C5, 0)
=IFNA(SWITCH(E5,"GG","Garden Gold","HC","Harbour Classic"), "Check code")
=IF(ISBLANK(C5), "", IFS(C5>150,0.18,C5>=60,0.15,TRUE,0.12))Choosing the right function on the exam
Performance-based tasks are worded in business language, not in function names, so part of the skill is recognizing which tool the task wants. The table below shows how Dagny translated typical task wording during her practice sessions.
| Task wording | Likely function |
|---|---|
| "Return High, Medium or Low based on the value" | IFS, or nested IF |
| "Display the region name for each region code" | SWITCH, or a lookup |
| "Mark rows where both conditions are met" | IF with AND |
| "Total sales for the West region in 2027" | SUMIFS |
| "How many orders exceeded 500" | COUNTIF or COUNTIFS |
| "Largest order for each product" | MAXIFS |
| "Use a name for the repeated calculation" | LET |
When a task names the function, use exactly that function even if another would give the same result: the exam checks the formula as well as the value in some tasks. When it does not, any correct formula that produces the required result is accepted. Dagny's habit was to read the whole task, underline the cells it named, and check whether it asked for a value or a formula before typing anything.
LET: naming parts of a formula
LET assigns names to values or calculations inside a formula, then uses those names in a final calculation. Its arguments are pairs of name and value, followed by the calculation. It makes long formulas shorter, easier to read and faster, because each named part is calculated once.
=LET(guests, C5,
rate, IFS(guests>150, 0.18, guests>=60, 0.15, TRUE, 0.12),
base, G5,
base*(1+rate))Without LET, the same formula repeats C5 three times inside the IFS and is hard to check. With LET, someone reading it sees that "rate" depends on "guests" and the result is "base times one plus rate". Names in LET follow the rules for defined names: they must start with a letter, cannot look like cell references (so not "A1" or "R2C3"), and exist only inside that formula. LET returns to the dynamic array lesson, where it is most useful.
LET also speeds up workbooks. In the package summary, Dagny's first version of the "average fee per guest" column called SUMIFS twice, once for fees and once for guests, in every row, and then repeated them inside an IF that guarded against division by zero. Rewritten with LET, each SUMIFS runs once: fees and guests are named, the IF tests the guests value, and the final division uses the names. On 430 rows the difference is small, but the same pattern on a 50,000-row export is the difference between a sheet that recalculates instantly and one that pauses every time a cell changes. The rule of thumb she gave Teo was simple: if the same expression appears twice in one formula, give it a name.
Worked problem
Untangling the quote formula
The old quote total was =G5+G5*IF(C5>150,0.18,IF(C5>=60,0.15,0.12))+IF(WEEKDAY(D5)=7,G5*0.1,0). Rewrite it with LET and IFS so each part has a name.
Show solution
- Name the base fee: base, G5.
- Name the service rate: rate, IFS(C5>150,0.18,C5>=60,0.15,TRUE,0.12).
- Name the weekend premium: premium, IF(WEEKDAY(D5)=7,0.1,0).
- Finish with the calculation: base*(1+rate+premium).
Answer: =LET(base,G5,rate,IFS(C5>150,0.18,C5>=60,0.15,TRUE,0.12),premium,IF(WEEKDAY(D5)=7,0.1,0),base*(1+rate+premium)). It returns the same result and each rule is readable on its own.
Common mistakes
MistakeEnding IFS without a catch-all test.
InsteadAdd TRUE as the last test so unmatched rows do not return #N/A.
MistakeTesting the smallest tier first in a nested IF or IFS.
InsteadOrder tests so the first TRUE result is the right one, usually largest threshold first.
MistakePutting the sum range last in SUMIFS.
InsteadSUMIFS, AVERAGEIFS, MAXIFS and MINIFS take the result range first.
MistakeWriting ">=J2" as a criterion.
InsteadJoin the operator to the cell: ">="&J2.
MistakeReading a MAXIFS result of 0 as a real value.
InsteadCheck COUNTIFS first; MAXIFS and MINIFS return 0 when nothing matches.
Summary and key terms
- IF can be nested; IFS lists ordered conditions and needs TRUE as a final catch-all.
- SWITCH matches one expression against exact values and accepts a default.
- AND, OR and NOT build compound conditions inside other functions.
- The IFS family sums, counts, averages and finds maximums and minimums with several criteria; SUMIF and AVERAGEIF put the result range last.
- LET names parts of a formula so they are calculated once and read clearly.
- Nested function
- A function used as an argument of another function.
- IFS
- A function that returns the result of the first TRUE condition in a list.
- SWITCH
- A function that matches an expression against values and returns the matching result.
- Criteria
- Text conditions such as ">=100" or "GG" used by conditional aggregation functions.
- MAXIFS
- A function that returns the largest value meeting one or more criteria.
- LET
- A function that assigns names to calculation results within a formula.
Practice problems
Work each problem on paper first, then reveal the answer to check.
What does IFS return when no test is TRUE?
Show answer
#N/A.
Which argument comes first in SUMIFS?
Show answer
The sum range.
Write a criterion for dates on or after the date in J2.
Show answer
">="&J2
Which function names intermediate results inside a formula?
Show answer
LET.
A SWITCH formula has three value and result pairs and no default. What does it return when nothing matches?
Show answer
#N/A, which is why a final default argument is good practice.
Why is IFNA often safer than IFERROR around a lookup?
Show answer
IFNA replaces only the not-found error, so other mistakes such as a wrong range or a typo in a name still show up and can be fixed.
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.