IF, AND, OR in Excel: Conditional Logic for Analysts

IF, AND, OR in Excel: Building Conditional Logic Without Losing Your Mind

IF
Returns one value if condition is true, another if false
AND
TRUE only when every condition is true
OR
TRUE when at least one condition is true
IFERROR
Catches any error and returns a fallback value

IF, AND, and OR are the conditional logic functions in Excel — and the source of more broken formulas, wrong outputs, and wasted analyst hours than nearly any other Excel feature. The syntax looks simple until you try to combine them, at which point the logic breaks down in ways that are hard to diagnose. This article covers exactly how IF, AND, OR, and IFERROR work individually, how to combine them correctly, and how to apply them to the real decisions analysts make in healthcare IT, QA tracking, and financial reporting workbooks.

How the IF Function Works — and What Each Argument Does

The IF function has three arguments: a logical test, a value to return if true, and a value to return if false.

=IF(logical_test, value_if_true, value_if_false)

Every argument has a specific role. Understanding what each one can and cannot contain prevents most IF formula errors before they happen.

ArgumentWhat it isWhat it can containCommon mistake
logical_testAny expression that evaluates to TRUE or FALSEComparisons (>, <, =, <>, >=, <=), AND(), OR(), another IF(), a cell containing TRUE/FALSEUsing = where you mean <>, or comparing text with wrong case assumptions
value_if_trueReturned when logical_test evaluates to TRUEText (in quotes), number, formula, another IF(), blank (“”)Forgetting quotes around text — Excel interprets unquoted text as a named range
value_if_falseReturned when logical_test evaluates to FALSESame options as value_if_true. Can be omitted — returns FALSE if missing.Omitting this argument when you want a blank — omitting returns the word FALSE, not empty

Text Comparisons: Case, Spaces, and the = Operator

Excel’s = operator is case-insensitive for text comparisons. =IF(A2="pass","✓","✗") treats “Pass”, “PASS”, and “pass” as identical. This is almost always the right behaviour for analyst work — but it means you cannot use IF to distinguish between uppercase and lowercase text. For that, you need EXACT: =IF(EXACT(A2,"PASS"),"exact match","no").

Leading and trailing spaces cause IF comparisons to fail silently. A cell containing “Pass ” (with a trailing space) does not match “Pass” in an IF test. If your IF formulas are returning false negatives on text that looks correct, wrap the cell reference in TRIM: =IF(TRIM(A2)="Pass","✓","✗"). Spaces in exported data from EHR systems, ticketing tools, and billing systems are one of the most common sources of this problem.

Numeric Comparisons and the Zero Problem

Numeric comparisons work exactly as expected with one exception: blank cells. A blank cell in Excel evaluates to zero in numeric comparisons. =IF(A2>0,"Has value","Empty") returns “Empty” for both a blank cell and a cell containing zero. If you need to distinguish between blank and zero, combine with ISBLANK: =IF(ISBLANK(A2),"No entry",IF(A2=0,"Zero entered","Has value")).

AND and OR: Multi-Condition Logic in Plain Language

AND and OR are not standalone decision-making functions — they are condition-building functions. Their job is to combine multiple logical tests into a single TRUE or FALSE result that an IF can act on.

AND returns TRUE only when every argument is TRUE. If even one is FALSE, AND returns FALSE. Think of AND as a checklist where every box must be checked.

OR returns TRUE when at least one argument is TRUE. It only returns FALSE when every argument is FALSE. Think of OR as a failover — if any condition is met, it passes.

Condition ACondition BAND(A,B)OR(A,B)Plain language
TRUETRUETRUETRUEBoth conditions met. Both tests pass.
TRUEFALSEFALSETRUEAND fails: not all conditions met. OR passes: at least one is met.
FALSETRUEFALSETRUESame as above — AND requires all; OR only needs one.
FALSEFALSEFALSEFALSENeither condition met. Both AND and OR return FALSE.

AND and OR Without IF: Direct Use

AND and OR can be used without IF when you only need a TRUE/FALSE result. A column that flags whether a record meets two criteria — without needing a custom label — can simply be =AND(B2="Inpatient",C2>5). The cell returns TRUE or FALSE. You can then filter on that column or use COUNTIF on it to count the matching records. The IF wrapper is only necessary when you want a custom value (text, number, another formula) instead of TRUE/FALSE.

Combining IF with AND and OR: The Patterns That Work

The structure for combining IF with AND or OR is always the same: AND or OR goes inside the first argument of IF, replacing the single logical test with a multi-condition test.

IF with AND: All Conditions Must Be True

=IF(AND(B2=”Inpatient”, C2>5, D2<>”Excluded”), “Flag”, “OK”)

This returns “Flag” only when the encounter type is Inpatient AND the LOS is greater than 5 AND the record is not marked Excluded. All three conditions must be true simultaneously. If any one fails, the formula returns “OK”. The AND function handles as many conditions as you need — there is no limit in current Excel versions, though readability breaks down past five or six conditions in a single AND.

IF with OR: Any Condition Triggers the Result

=IF(OR(C2=”Denied”, C2=”Pending”, C2=”On Hold”), “Needs Review”, “Cleared”)

This returns “Needs Review” if the claim status is any of three values. The OR function is more efficient than writing IF(C2="Denied","Needs Review",IF(C2="Pending","Needs Review",IF(C2="On Hold","Needs Review","Cleared"))) — same result, less nesting, less chance of bracket errors.

IF with Both AND and OR: Complex Multi-Condition Tests

You can nest AND and OR inside each other to build compound conditions. The key is to be deliberate about which operator wraps which conditions:

— Flag if: claim is denied AND (payer is BCBS OR payer is UHC)
=IF(AND(C2=”Denied”, OR(D2=”BCBS”, D2=”UHC”)), “Priority Review”, “Standard”)

The outer AND requires both sub-conditions to be true: the claim must be denied, and the payer must be one of the two named payers. The inner OR handles the payer alternatives. Read complex IF/AND/OR formulas from inside out — evaluate the innermost parentheses first, then work outward.

The Bracket Test

Before pressing Enter on any IF formula with AND or OR, count the opening and closing parentheses. They must match. Excel’s formula bar colours matching bracket pairs — hover over any bracket and Excel highlights its partner. A bracket count mismatch is the most common reason IF formulas return a parse error rather than a result.

Nested IF: Multiple Outcomes from a Single Formula

A nested IF places another IF inside the value_if_false argument of the outer IF, creating a chain of conditions that returns different results depending on which condition is met first. This is the Excel equivalent of an if/else if/else structure in programming.

=IF(C2>=90, “Pass – High”,
IF(C2>=75, “Pass – Standard”,
IF(C2>=60, “Marginal”,
“Fail”)))

Excel evaluates nested IF conditions from the outside in, stopping at the first condition that is TRUE. Sequence matters. If you wrote the 60% condition before the 90% condition, every score above 60% would return “Marginal” because that condition would be met first and the formula would stop evaluating. Always order nested IF conditions from most restrictive to least restrictive.

The Nesting Limit and Readability Problem

Excel supports up to 64 nested IF levels in current versions. The practical limit for readable, maintainable analyst formulas is three to four levels. Beyond that, diagnosing which condition branch produced a result requires tracing each argument manually. A nested IF with seven levels is not a formula — it is a maintenance liability. When you reach four nested levels, switch to IFS.

One technique for improving nested IF readability: use Alt+Enter to add line breaks inside the formula bar. Excel allows multi-line formula entry. The formula above is written across four lines deliberately — each IF on its own line makes the logic visible at a glance. The formula still works identically; the line breaks are purely cosmetic.

IFS Function: The Readable Alternative to Nested IF

IFS (available in Microsoft 365 and Excel 2019+) removes the nesting structure entirely. Instead of IF inside IF inside IF, you list condition-result pairs sequentially:

=IFS(C2>=90, “Pass – High”,
C2>=75, “Pass – Standard”,
C2>=60, “Marginal”,
TRUE, “Fail”)

Each pair is: condition, result_if_true. IFS evaluates conditions in order, returns the result paired with the first TRUE condition, and stops. The final TRUE, "Fail" acts as the else clause — since TRUE is always true, it catches anything that did not match an earlier condition. Without a final TRUE catch-all, IFS returns an error (#N/A) if no condition is met.

DimensionNested IFIFS
ReadabilityDecreases rapidly with each added levelLinear — condition/result pairs read left to right
Version availabilityAll Excel versionsMicrosoft 365 and Excel 2019+ only
Default fallbackThe last value_if_false is the defaultMust add TRUE as a final condition or IFS returns #N/A
Adding a new conditionRequires editing nested structure — can break bracketsAdd a condition-result pair — minimal editing risk
Best forWorkbooks shared with older Excel versions, 2-3 condition formulas4+ condition outcomes, workbooks on Microsoft 365

IFERROR and IFNA: Handling Errors Gracefully

IFERROR wraps any formula and intercepts any error that formula might return — #N/A, #REF!, #VALUE!, #DIV/0!, #NAME?, #NULL!, #NUM!. If the wrapped formula produces an error, IFERROR returns the fallback value instead. If it produces a valid result, IFERROR passes that result through unchanged.

=IFERROR(VLOOKUP(A2,CodeTable,2,FALSE), “Code not found”)

Without IFERROR, a VLOOKUP that cannot find its lookup value returns #N/A. With IFERROR, it returns “Code not found” — which is meaningful in a report and does not disrupt any downstream calculations that reference this cell.

IFERROR vs IFNA: The Important Distinction

IFNA catches only #N/A errors. All other error types pass through unchanged. This distinction matters when you want to handle “not found” gracefully but still see #REF! or #VALUE! errors — because those indicate a different problem that should not be silently suppressed.

For VLOOKUP and XLOOKUP, use IFNA rather than IFERROR when the only expected error is “lookup value not in table.” If your lookup returns a #REF! or #VALUE!, that signals a broken reference or wrong data type — you want to see that error, not suppress it. IFERROR hides all errors including structural problems. IFNA is the more precise tool for lookup functions.

The IFERROR Trap

Wrapping every formula in IFERROR is not a best practice — it is error suppression. A formula that returns #REF! is telling you something is broken. Silencing it with IFERROR produces a report that looks complete but contains hidden structural failures. Use IFERROR deliberately, only for expected and handled error conditions. Use IFNA for lookup not-found scenarios. Leave structural errors visible.

Real Analyst Scenarios: Healthcare IT, QA, and Finance

Scenario 1 — Healthcare IT: Epic UAT Status Classification

Context

During an Epic EHR implementation, a BA analyst maintains a UAT test case log across eight modules. Each row has a Status column (Pass/Fail/Blocked/Not Run) and a Severity column (Critical/High/Medium/Low) for failed test cases. The analyst needs a Priority column that classifies each row for the daily triage meeting, and a separate Sign-Off column showing whether the module is ready for clinical sign-off.

Priority classification — three levels based on status and severity combined:

=IF(AND(B2=”Fail”, C2=”Critical”), “P1 – Immediate”,
IF(AND(B2=”Fail”, C2=”High”), “P2 – Same Day”,
IF(OR(B2=”Fail”, B2=”Blocked”), “P3 – This Cycle”,
IF(B2=”Not Run”, “P4 – Schedule”,
“Resolved”))))

The logic: Critical failures are P1. High failures are P2. Any other Fail or Blocked (regardless of severity) is P3. Not Run is P4. Everything else (Pass) is Resolved. The nesting order matters — Critical and High are evaluated before the general Fail/Blocked catch, so they never fall into P3 accidentally.

Module-level sign-off readiness — using COUNTIFS with an IF wrapper:

=IF(
AND(
COUNTIFS(ModuleLog[Module],$A2,ModuleLog[Status],”Fail”)=0,
COUNTIFS(ModuleLog[Module],$A2,ModuleLog[Status],”Blocked”)=0,
COUNTIFS(ModuleLog[Module],$A2,ModuleLog[Status],”Not Run”)=0
),
“✓ Ready for sign-off”,
“✗ Not ready”
)

This returns “Ready for sign-off” only when the module has zero fails, zero blocked, and zero not-run test cases. All three counts must be zero — AND is the right operator. If any count is greater than zero, the module is not ready. This pattern is described in the context of BAT vs UAT acceptance criteria — the sign-off condition is precisely this kind of multi-condition gate.

Scenario 2 — Revenue Cycle: Claim Routing and Denial Flag

Context

A revenue cycle analyst is building a monthly denial review workbook. The raw export has claim status, payer name, denial reason code, and claim amount. She needs three derived columns: a Review Required flag, a Denial Category for grouping, and an Escalation label for claims that exceed a dollar threshold and are denied by specific payers.

Review Required — any claim that is denied, pending, or on hold:

=IF(OR(C2=”Denied”, C2=”Pending”, C2=”On Hold”), “Review”, “”)

Denial Category — using IFS for multiple denial code groupings:

=IFS(
OR(D2=”15″, D2=”197″), “Prior Authorization”,
OR(D2=”CO-4″, D2=”CO-5″), “Coding Error”,
D2=”CO-22″, “Coordination of Benefits”,
OR(D2=”CO-16″, D2=”CO-96″),”Missing Information”,
C2<>”Denied”, “Not Denied”,
TRUE, “Other Denial”
)

Escalation — denied by priority payers AND above dollar threshold:

=IF(AND(C2=”Denied”, OR(B2=”BCBS”,B2=”UHC”,B2=”Aetna”), E2>DenialEscalationThreshold),
“⚠ Escalate”, “”)

DenialEscalationThreshold is a named range pointing at the threshold value on a Config sheet. The formula flags the claim only when all three conditions are met: denied status, one of the three named payers, and claim amount above threshold. This is exactly the AND/OR nesting pattern described earlier — AND for the overall gate, OR for the payer alternatives.

Scenario 3 — QA: Test Data Validation with Multi-Condition Logic

A QA analyst is validating a data migration from a legacy patient registration system to Epic Prelude. The validation requires checking that each migrated record has a valid MRN (not blank), a valid encounter type from an allowed list, and an admission date within an acceptable range. A single validation formula per row checks all three:

=IF(
AND(
NOT(ISBLANK(A2)),
OR(B2=”Inpatient”, B2=”Outpatient”, B2=”ED”, B2=”Observation”),
AND(C2>=MigrationStartDate, C2<=MigrationEndDate)
),
“Valid”,
IF(ISBLANK(A2), “Error: Missing MRN”,
IF(NOT(OR(B2=”Inpatient”,B2=”Outpatient”,B2=”ED”,B2=”Observation”)),
“Error: Invalid Encounter Type”,
“Error: Date Out of Range”))
)

This formula validates first. If all conditions pass, it returns “Valid”. If validation fails, the nested IF in the false branch diagnoses which specific condition failed and returns the appropriate error label. The analyst can filter on this column to see exactly which validation rule each failed record violated — without checking each field manually. This ISTQB-aligned data validation approach — testing preconditions before accepting a test case as valid input — applies equally to SQL-based validation in Epic Clarity and to Excel-based export review.

The Six Most Common IF Logic Mistakes

#MistakeWhat happensFix
1Forgetting quotes around text values=IF(A2=Pass,"✓","✗") — Excel treats Pass as a named range, returns #NAME? error=IF(A2="Pass","✓","✗") — text in the logical test always needs double quotes
2Wrong nesting order in multiple conditionsA less specific condition catches records meant for a more specific condition. All scores above 60 return “Marginal” instead of “Pass – High”.Always order nested IF from most restrictive (highest score, most specific match) to least restrictive.
3Omitting the false argument=IF(A2="Pass","✓") returns the word FALSE (not blank) when the condition is not met. Looks like a text value in the column.Use =IF(A2="Pass","✓","") if you want blank when false. Never rely on the omitted false argument to produce a blank.
4Using IF instead of AND/OR for multi-condition logic=IF(A2="Denied",IF(B2="BCBS","Flag",""),"") — three nested levels for what AND handles in one: =IF(AND(A2="Denied",B2="BCBS"),"Flag","")When multiple conditions must all be true, use AND. When any condition suffices, use OR. Save nesting for different outcomes.
5Wrapping everything in IFERROR unnecessarilyStructural errors (#REF!, #VALUE!) are silently hidden. The workbook looks complete but contains broken formulas that produce wrong numbers.Use IFERROR only for genuinely expected and handled conditions. Use IFNA for lookup not-found. Leave structural errors visible.
6Comparing numeric text as numbersA denial code “197” stored as text does not equal the number 197 in an IF comparison. =IF(D2=197,...) returns false even when the cell displays 197.Use =IF(D2="197",...) for text-stored codes, or =IF(VALUE(D2)=197,...) if the type is uncertain. Always check cell alignment — left-aligned numbers are usually stored as text.

Complex Logic Patterns: When to Use CASE WHEN Thinking

Analysts who work with SQL alongside Excel often find SQL’s CASE WHEN structure more intuitive than nested IF. The mental model maps directly: CASE WHEN is IFS, WHERE clause conditions are AND/OR, and the ELSE clause is the final TRUE fallback. If you think in CASE WHEN, you can translate to IFS directly.

SQL CASE WHEN
CASE
WHEN Status=’Denied’
AND Payer IN (‘BCBS’,’UHC’)
AND Amount > 1000
THEN ‘Escalate’
WHEN Status=’Denied’
THEN ‘Standard Review’
WHEN Status=’Pending’
THEN ‘Monitor’
ELSE ‘Cleared’
END
Excel IFS Equivalent
=IFS(
AND(C2=”Denied”,
OR(B2=”BCBS”,B2=”UHC”),
E2>1000), “Escalate”,
C2=”Denied”, “Standard Review”,
C2=”Pending”, “Monitor”,
TRUE, “Cleared”
)

The translation is mechanical. Each WHEN becomes an IFS condition. The AND in SQL becomes AND() in Excel. IN (‘BCBS’,’UHC’) becomes OR(B2=”BCBS”,B2=”UHC”). ELSE becomes TRUE. This mental mapping works in both directions — analysts who write Excel formulas can read SQL logic, and SQL analysts can translate to Excel without re-learning the decision structure. For analysts who work across both tools, the SQL Learning Hub covers CASE WHEN in depth alongside the data validation query patterns that complement Excel conditional logic.

When IF Logic Reaches Its Limits: Switch to XLOOKUP or SUMIFS

IF, AND, and OR are the right tools when conditions involve comparisons and the outcome set is small (two to eight results). When the number of possible outcomes grows beyond eight, or when each outcome is driven by a lookup against a reference table rather than a hardcoded value, IF becomes the wrong tool.

A formula like =IF(D2="15","Prior Auth",IF(D2="CO-4","Coding Error",IF(D2="CO-22","COB",...))) with 20 denial codes is not a formula — it is a maintenance problem. Convert the denial code-to-category mapping to a lookup table and use XLOOKUP or a VLOOKUP against it. The table is maintainable, auditable, and extensible. The nested IF is not.

Similarly, when the conditional logic involves aggregations (count how many records meet these conditions, sum the amounts for records matching these criteria), SUMIFS and COUNTIFS are more appropriate than IF. Use IF for row-level decisions. Use SUMIFS and COUNTIFS for aggregate-level decisions. The two tool categories are complementary, not interchangeable.

Building a Decision Framework Before Writing the Formula

Complex IF logic written directly into the formula bar before the logic is mapped produces formulas that are hard to debug. The faster approach — write out the decision as a plain-language table first, then translate to formula syntax.

ConditionOperatorAdditional conditionResult
Status = DeniedANDPayer is BCBS OR UHC AND Amount > $1,000Escalate
Status = Denied(no additional)Standard Review
Status = Pending(no additional)Monitor
None of the aboveCleared

Once the logic is mapped in a table, translating each row to an IFS condition-result pair takes less than two minutes. The table also serves as documentation — paste it into a comment or a Notes sheet alongside the workbook so the next analyst who opens it can understand the logic without reverse-engineering the formula. This practice aligns with BABOK v3’s guidance on requirements traceability — the decision table is the documented business rule; the formula is its implementation.

Debugging a Formula That Returns the Wrong Value

When an IF formula returns an unexpected value, the fastest debugging approach is to evaluate each argument in isolation. Click the cell, open the formula bar, and use Formulas → Evaluate Formula. Excel steps through each sub-expression showing its current value. You can see exactly where the condition evaluates differently from your expectation.

Alternatively, break the formula into temporary helper columns. Put the AND() or OR() test result in one column (it shows TRUE or FALSE), then have the IF reference that column. Seeing TRUE or FALSE explicitly in a cell makes it immediately obvious whether the condition is evaluating as intended. Remove the helper columns once the formula is verified.

The IF and conditional logic patterns in this article — UAT classification, denial categorisation, migration validation — are foundational to the Excel-based analyst workbooks described in the Excel for IT Analysts hub. The SUMIFS patterns that complement IF for aggregate-level decisions are covered in a separate article on SUMIFS, COUNTIFS, and conditional aggregation without pivot tables.

NOT Function: Reversing a Condition

NOT reverses the result of a logical expression. NOT(TRUE) returns FALSE. NOT(FALSE) returns TRUE. It is the fourth conditional function that completes the core set, though it appears less often because most conditions can be expressed directly without reversal.

NOT is useful when the positive condition is harder to express than the negative. Instead of listing all the statuses that qualify for a flag, you can exclude the one that does not:

— These are equivalent:
=IF(OR(C2=”Denied”,C2=”Pending”,C2=”Blocked”,C2=”Not Run”),”Flag”,””)— Simpler with NOT when only one status doesn’t qualify:
=IF(NOT(C2=”Pass”),”Flag”,””)

NOT also appears in combination with ISBLANK, ISERROR, and ISNUMBER for data validation:

=IF(NOT(ISBLANK(A2)),”Has value”,”Empty”) — cleaner than IF(A2<>””,”Has value”,”Empty”)
=IF(NOT(ISNUMBER(B2)),”Not a number”,”OK”) — catches text-stored numbers

IF with Date Logic: Common Patterns for Analyst Reporting

Date comparisons in IF work exactly like numeric comparisons because Excel stores dates as serial numbers. A date in a cell is just a number — 45000 for some date in 2023, for example — formatted to display as a date. This means all standard comparison operators work: >, <, =, <=, >=.

Overdue Flagging

— Flag defects open more than 5 business days
=IF(AND(NETWORKDAYS(B2,TODAY())>5, C2<>”Resolved”), “Overdue”, “”)— Categorise by age bracket
=IFS(
NETWORKDAYS(B2,TODAY())>10, “Critical – Overdue”,
NETWORKDAYS(B2,TODAY())>5, “Warning – Approaching”,
C2=”Resolved”, “Closed”,
TRUE, “Active”
)

NETWORKDAYS calculates business days between two dates, excluding weekends. For defect aging, incident SLA tracking, and claim follow-up deadlines, NETWORKDAYS inside IF produces the business-day-aware flag that DATEDIFF alone cannot. Add a holidays range as the third argument to NETWORKDAYS if your organisation tracks public holidays: =NETWORKDAYS(B2,TODAY(),Holidays).

Period Membership: Is a Date in This Quarter?

— Check whether a claim date falls within the reporting period
=IF(AND(B2>=PeriodStart, B2<=PeriodEnd), “In Period”, “Out of Scope”)— Alternative using named ranges from Config sheet
=IF(AND(B2>=ReportStart, B2<ReportEnd), “In Period”, “Out of Scope”)

Note the use of < rather than <= for the end date in the second example. This half-open interval pattern (>= start AND < end) avoids including the first day of the next period when the end date is set to the first day of the following month. It is the same interval pattern used in SQL date filtering and produces consistent results whether the date includes a time component or not.

IF with Text Functions: Building Conditional Text Output

The value_if_true and value_if_false arguments of IF can contain any formula, including text concatenation. This is the pattern for building conditional narrative labels, reference strings, or formatted outputs that change based on the data in each row.

— Build a status label that includes the count
=IF(
COUNTIFS(TestLog[Module],A2,TestLog[Status],”Fail”)=0,
“✓ ” & A2 & ” — all tests passed”,
“✗ ” & A2 & ” — ” &
COUNTIFS(TestLog[Module],A2,TestLog[Status],”Fail”) &
” failures remaining”
)

This formula produces: “✓ Willow — all tests passed” or “✗ Willow — 3 failures remaining” depending on the failure count. The ampersand (&) concatenates text and formula results. The COUNTIFS inside the false branch calculates the count only when the module has failures — it does not run the count calculation for passing modules. This pattern produces self-describing cells that are readable in a sign-off report without requiring a separate column.

Conditional Formatting Driven by IF Logic

IF formula logic also powers conditional formatting rules. When you apply a conditional format using a formula, the formula works exactly like a cell formula — if it returns TRUE, the format applies. This is how analysts build status dashboards where cells automatically turn red for failures, amber for warnings, and green for passes — without manual formatting.

The formula in a conditional format rule uses the same IF, AND, OR syntax as a cell formula, but it only needs to return TRUE or FALSE — not a label. To highlight the entire row red when Status is “Fail” and Severity is “Critical”, select the entire row range and apply a conditional format with this formula:

=AND($C2=”Fail”, $D2=”Critical”)

Note the mixed references: $C2 and $D2 lock the columns (always C and D) but leave the rows relative so the rule evaluates each row independently. This is the absolute vs relative reference pattern applied to conditional formatting — the same principle as in cell formulas. Without the column lock ($C), the conditional format would shift the column reference as it evaluates cells across the row, producing wrong results.

IF Logic and Power Query: When to Move the Decision Upstream

IF, AND, OR formulas operate at the cell level — they run row by row after data has been loaded into the worksheet. For complex classification logic applied to large datasets (10,000+ rows), the same logic runs more efficiently and more maintainably in Power Query’s custom column step, before the data reaches the worksheet.

Power Query’s M language conditional syntax is if condition then result else result — lowercase, without the function wrapper. The AND equivalent is the word and, OR equivalent is or:

// Power Query M language — Add Custom Column
if [Status] = “Denied” and ([Payer] = “BCBS” or [Payer] = “UHC”)
and [Amount] > 1000
then “Escalate”
else if [Status] = “Denied”
then “Standard Review”
else if [Status] = “Pending”
then “Monitor”
else “Cleared”

The logic is identical to the IFS formula — it reads as plain English and maps directly from the decision table. Moving the classification to Power Query means the Category column appears in the loaded data before any worksheet formulas run. The worksheet formulas that reference it can then use straightforward COUNTIF or SUMIF patterns rather than embedding the classification logic in each formula separately.

The general rule: keep IF logic in worksheet cells when the dataset is small, the logic is simple, and the workbook is shared with colleagues who need to understand and edit the formulas directly. Move it to Power Query when the dataset is large, the logic is complex, or the classification needs to run before the data is loaded. Both approaches are valid — the choice depends on the workbook’s scale and maintenance context.

The Practice That Prevents Most IF Logic Errors

Write the decision logic as a plain-language table before you open the formula bar. Map each condition, the operator connecting it to the next condition, and the result it produces. Then translate each row to an IFS condition-result pair. This takes three minutes and prevents the mismatched brackets, wrong nesting order, and silent wrong values that come from writing complex conditional logic directly without a structure to follow. The table also becomes your documentation — something the analyst who inherits the workbook six months later will thank you for.

Authoritative References

Downloads

📊
IF, AND, OR Practice Workbook (Excel)
Four tabs: IF basics with healthcare IT examples, AND/OR truth table exercises, nested IF vs IFS comparison, and a UAT classification formula with the denial routing scenarios from this article. Each tab includes the correct formula and a common mistake version to compare.

Download Workbook (Excel)

📋
IF Logic Quick Reference Card (PDF)
One-page reference covering IF/AND/OR/IFERROR/IFS syntax, the AND/OR truth table, six common mistakes with fixes, the CASE WHEN to IFS translation guide, and the decision table template for mapping logic before writing formulas.

Download Reference Card (PDF)

Scroll to Top