How to One Or The Other Not Both in Excel
Learn multiple Excel methods to one or the other not both with step-by-step examples and practical applications.
How to One Or The Other Not Both in Excel
Why This Task Matters in Excel
In day-to-day business analysis you frequently face situations where two separate conditions can be true, yet for reporting, compliance, or bonus calculations you want to count the record only when exactly one of those conditions is satisfied. Think of onboarding processes where an employee can supply either a passport or a driver’s licence, but not both; marketing campaigns where a discount applies to customers who bought product A or product B, yet customers who purchased both should not get a double perk; or financial controls where revenue is flagged if recognised in either the current month or the prior month, but double-recognition must be avoided.
“One or the other, not both” logic is formally called an exclusive OR (XOR). Mastering this pattern allows you to build unambiguous dashboards, prevent double-counting, and comply with policy rules that treat mutual exclusivity as a critical criterion. Because Excel is often the first stop for operational data, being able to implement XOR tests directly in the worksheet saves time otherwise spent exporting to databases or writing custom code.
Across industries the need arises: healthcare claims processing (patient must have procedure A or procedure B but not both for a reimbursement code), education (course credit applies if student completed module X or module Y but dual credit is disallowed), and manufacturing (machine can be in maintenance or production state, not simultaneously). Failing to enforce exclusivity can lead to erroneous totals, incorrect bonuses, or compliance violations. The ability to embed XOR logic seamlessly integrates with other Excel skills such as PivotTables, conditional formatting, and dynamic arrays, forming a foundation for robust analytics pipelines.
Best Excel Approach
Excel offers several pathways to model exclusive OR. The modern, simplest approach is the dedicated XOR function, introduced in Excel 2013, which directly returns TRUE when an odd number of logical tests are TRUE. For workbooks that must remain compatible with older versions, you can recreate XOR logic with a combination of logical operators such as OR, AND, and NOT.
The choice depends on environment and readability. If you are certain your users have Excel 2013 or later, use XOR for clarity. If you maintain shared templates for mixed environments (for example, some users on Excel 2010), stick to a composite formula.
Typical syntax using XOR for two tests:
=XOR(logical1, logical2)
Where:
- logical1 – first test that returns TRUE or FALSE
- logical2 – second logical test
Alternate formula without XOR:
=AND(OR(test1, test2), NOT(AND(test1, test2)))
Logic breakdown
- OR(test1, test2) checks that at least one test is TRUE.
- AND(test1, test2) checks if both are TRUE.
- NOT(AND(...)) ensures both are not simultaneously TRUE.
- AND(… , …) combines the two pieces, yielding TRUE only when exactly one test passes.
Parameters and Inputs
Before writing formulas, clarify your two logical tests:
-
Tests can be direct comparisons, Boolean fields, or nested formulas.
Example: A\1=\"Yes\", B\1=\"Yes\"
Example: A1 greater than 1000, B\1=\"North\" -
Data types: Numbers, text, dates, or booleans are all acceptable as long as the comparison results in TRUE or FALSE.
-
Optional parameters: XOR can accept more than two arguments; the logic still returns TRUE when the overall count of TRUEs is odd. When you intend strict two-test exclusivity, supply only two arguments.
-
Data preparation: Remove blanks or convert “Y”/“N” texts to TRUE/FALSE to avoid unexpected FALSE positives caused by hidden spaces.
-
Validation: Ensure no unintended data conversions (e.g., numbers stored as text).
-
Edge cases: Both blanks or both FALSE evaluate to FALSE. If blanks should be ignored, wrap individual tests in functions like IF(A\1=\"\",FALSE,A\1=\"Yes\").
Step-by-Step Examples
Example 1: Basic Scenario
Imagine a small membership list. A member qualifies for a promotional gift if they have completed either an online survey or a product review, but not both.
Sample data in [A2:C6]:
- Column A – Member Name
- Column B – Survey Completed? (TRUE/FALSE)
- Column C – Review Submitted? (TRUE/FALSE)
Step-by-step:
-
Enter the sample booleans:
Row 2 – TRUE, FALSE
Row 3 – TRUE, TRUE
Row 4 – FALSE, TRUE
Row 5 – FALSE, FALSE -
In D2 label column “Gift Eligible”.
-
In D2 type:
=XOR(B2, C2)
- Copy down to D5.
Expected results:
- Row 2 returns TRUE (only survey).
- Row 3 returns FALSE (both).
- Row 4 returns TRUE (only review).
- Row 5 returns FALSE (neither).
Why it works: XOR evaluates two logical inputs; an odd count of TRUEs (one) returns TRUE, zero or two returns FALSE. Common variation: change data entry from TRUE/FALSE to “Yes”/“No”; adapt test to B\2=\"Yes\".
Troubleshooting tip: Mixed capitalisation (“yes” vs “Yes”) can break string comparisons. Use UPPER or LOWER to normalise, or data validation drop-downs.
Example 2: Real-World Application
A retailer tracks monthly purchases. A customer receives a “first-time customer” voucher if they bought in January or February but not both, preventing multiple vouchers.
Data layout:
- Column A – Customer ID
- Column B – January Spend
- Column C – February Spend
- Column D – Voucher?
Business rules: Spend greater than zero qualifies.
- Build test columns E and F (hidden or off to the side) to convert the spends into booleans:
=E2: =B2>0
=F2: =C2>0
- In D2 calculate exclusivity with version-neutral formula:
=AND(OR(E2, F2), NOT(AND(E2, F2)))
- Copy downward for 50 000 customers. Add a PivotTable summarising voucher counts.
Integration with other features:
- Conditional formatting colouring Voucher? TRUE rows.
- SUMIFS to total voucher value (voucher amount in Column E) based on TRUE.
Performance considerations: The composite XOR formula is light; however, testing sales greater than zero across large datasets can be volatile if you reference entire columns. Restrict ranges to actual data rows.
Example 3: Advanced Technique
A manufacturing plant logs machine states: “Maintenance”, “Production”, or blank. The control report must highlight shifts where exactly one of two critical machines (Machine 1, Machine 2) was under Maintenance.
Dataset:
- Column A – Shift Date/Time
- Column B – Machine 1 State
- Column C – Machine 2 State
Potential states: “Maintenance”, “Production”, blank.
Advanced challenges:
- Text comparisons
- Dynamic spill range for new rows
- Error handling for unexpected states
- In D2 create a helper column returning TRUE when the state equals “Maintenance”:
=IFERROR(B2="Maintenance", FALSE)
-
In E2 similar for Machine 2.
-
In F2 evaluate exclusivity using XOR with dynamic arrays (Office 365):
=XOR(D2#, E2#)
Here D2# and E2# are spill references if you converted helper formulas into dynamic arrays. The spill notation recalculates automatically for new rows.
- For dashboards, aggregate with:
=COUNTIFS(F2#, TRUE)
Edge case management: IFERROR returns FALSE for blank or unexpected text, preventing N/A from breaking the XOR.
Performance optimisation: Use structured references in Excel tables. Convert data range to a table named tblShifts; the XOR formula becomes =)
=XOR([@M1_Maint], [@M2_Maint])
Professional tip: Document assumptions (only “Maintenance” considered downtime). Store them in a dedicated Notes sheet.
Tips and Best Practices
- Prefer XOR for readability when available; readers instantly understand the intent.
- Wrap each logical test inside ISNUMBER, ISTEXT, or IFERROR when data quality is uncertain.
- Convert your range to an Excel Table so formulas like [@Survey] become self-documenting and expand automatically.
- Use helper columns for intermediate tests instead of nesting lengthy expressions; this simplifies auditing.
- Combine with conditional formatting to make TRUE results visually pop without additional steps.
- For repeated use, store the XOR template in Personal Macro Workbook or a custom add-in to standardise across files.
Common Mistakes to Avoid
- Using OR instead of XOR – OR returns TRUE when either or both conditions are true, causing double-counting. Spot this when totals seem inflated. Correct by replacing OR with XOR or composite formula.
- Forgetting to wrap comparisons in parentheses, leading to operator precedence errors. If results appear inconsistent, add parentheses around each test before feeding them into XOR or AND.
- Comparing numbers stored as text; the logical test B2 greater than 0 will return FALSE when B2 is “10” (text). Fix by converting to numeric with VALUE or multiplying by 1.
- Copying XOR formulas into older Excel versions. Users on Excel 2010 will see #NAME?. Provide a compatibility alternative or use an IFfunction wrapper checking for the hash.
- Neglecting blanks: blank cells can unintentionally qualify. Use LEN(A1)>0 to ensure presence of data rather than A1<>\"\" which overlooks hidden spaces.
Alternative Methods
Below is a comparison of three ways to implement exclusivity:
| Method | Syntax (two tests) | Pros | Cons | Best For |
|---|---|---|---|---|
| XOR function | `=XOR(`test1, test2) | Short, clear, supports many conditions, dynamic array compatible | Requires Excel 2013+, not supported in legacy | Modern corporate environments |
| AND/OR/NOT combo | `=AND(`OR(test1,test2),NOT(AND(test1,test2))) | Backward compatible to Excel 2003, transparent logic | Longer, harder to read, easy to mistype | Mixed-version workbooks |
| Arithmetic approach | =(test1+test2)=1 | Very short, works because TRUE=1, FALSE=0 | Less readable, may break if tests are non-Boolean, fails with text TRUE/FALSE | Quick ad-hoc analysis by advanced users |
When migrating, wrap the newer XOR in IFERROR to fall back:
=IFERROR(XOR(test1, test2), AND(OR(test1,test2), NOT(AND(test1,test2))))
FAQ
When should I use this approach?
Use it whenever policy dictates mutual exclusivity, such as discount eligibility, risk flags, or compliance checks. It is especially important in financial models where double counting leads to material misstatements.
Can this work across multiple sheets?
Yes. Reference the tests directly:
=XOR(Sheet1!B2="Yes", Sheet2!C2>0)
Ensure both sheets calculate before dependent sheets to avoid circular references.
What are the limitations?
XOR allows more than two arguments, but the logic becomes “odd number of TRUEs” rather than exactly one. If you add a third test and need “exactly one”, revert to a SUM approach =(test1+test2+test3)=1.
How do I handle errors?
Wrap each test in IFERROR, or use IF(OR(ISERROR(test1),ISERROR(test2)), FALSE, XOR(test1,test2)). This prevents a single N/A from propagating.
Does this work in older Excel versions?
The XOR function does not. Use the AND/OR/NOT formula for versions earlier than 2013, including Excel for Mac 2011. All logical operators themselves are fully backward compatible.
What about performance with large datasets?
Logical formulas are lightweight. Bottlenecks arise from volatile functions or referencing entire columns. Convert data ranges to tables, limit rows in calculations, and disable automatic calculation while bulk pasting new data.
Conclusion
Knowing how to enforce “one or the other, not both” logic is pivotal for building trustworthy Excel models. Whether you rely on the dedicated XOR function or craft a compatibility formula, the ability to flag mutually exclusive conditions prevents costly errors, streamlines decision-making, and opens the door to more advanced analytical techniques. Practice with the examples, adopt the recommended best practices, and you will find XOR logic becoming second nature as you tackle increasingly complex spreadsheets.
Related Articles
How to Show the 10 Most Common Text Values in Excel
Learn multiple Excel methods to list the 10 most frequent text values—complete with step-by-step examples, business use cases, and expert tips.
How to Abbreviate Names Or Words in Excel
Learn multiple Excel methods to abbreviate names or words with step-by-step examples and practical applications.
How to Abbreviate State Names in Excel
Learn multiple Excel methods to abbreviate state names with step-by-step examples, professional tips, and real-world applications.