XOR Function in Excel: Exactly One Condition True
By ExcelReady TeamUpdated 7 min read
The short answer
XOR returns TRUE when exactly one of two conditions is TRUE, and FALSE when both are TRUE or both are FALSE. For example, =XOR(B2="Yes",C2="Yes") flags orders that are paid but not shipped, or shipped but not paid. With three or more conditions, XOR returns TRUE when an odd number of them are TRUE. It needs Excel 2013 or later.
Key takeaways
- XOR means exclusive OR: one or the other, but not both.
- With two conditions, XOR is TRUE when exactly one is TRUE. OR is also TRUE when both are.
- With three or more conditions, XOR is TRUE when an odd number are TRUE, not only when exactly one is.
- For exactly one of many, count the TRUE tests instead: =COUNTIF(B2:D2,"Yes")=1.
- Wrap XOR in IF to show a label such as Check or OK instead of TRUE or FALSE.
On this page+
The XOR function in Excel answers the question "is exactly one of these true?". It returns TRUE when one condition is TRUE and the other is FALSE, and FALSE when both match. That makes it a quick way to spot mismatches, such as an order that was paid but never shipped. This guide shows how XOR works, how it differs from OR, and the one trap with three or more conditions.
What does the XOR function do?#
XOR stands for "exclusive OR": one or the other, but not both. Its syntax is:
=XOR(logical1, [logical2], ...)Each argument is a logical test, which is any expression that gives TRUE or FALSE, such as B2="Yes" or C2>100. You can give up to 254 of them. XOR is available in Excel 2013 and later, including Microsoft 365 and Excel for the web.
With two conditions, the result follows this truth table:
| Condition 1 | Condition 2 | OR | XOR |
|---|---|---|---|
| TRUE | TRUE | TRUE | FALSE |
| TRUE | FALSE | TRUE | TRUE |
| FALSE | TRUE | TRUE | TRUE |
| FALSE | FALSE | FALSE | FALSE |
The only row where OR and XOR differ is the first one: when both conditions are TRUE, OR says TRUE and XOR says FALSE. The guide to AND, OR and NOT covers the other logical functions.
XOR example: find orders that don't match#
XOR is most useful for finding rows where two things should agree but don't. In this order list, every order should be both paid and shipped, or neither:
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Order | Paid | Shipped | Mismatch? |
| 2 | 1001 | Yes | Yes | |
| 3 | 1002 | Yes | No | |
| 4 | 1003 | No | No | |
| 5 | 1004 | No | Yes | |
| 6 | 1005 | Yes | Yes | |
| 7 | 1006 | Yes | No |
In D2, type this and fill down to D7 (Windows: Ctrl+D; Mac: ⌘D):
=XOR(B2="Yes",C2="Yes")The results are FALSE, TRUE, FALSE, TRUE, FALSE, TRUE. Orders 1002 and 1006 are paid but not shipped, and order 1004 was shipped without payment. Orders where both columns agree, whether Yes and Yes or No and No, return FALSE.
The same idea works for two reviewers who should agree (=XOR(B2="Approve",C2="Approve")), or a form where a person should tick exactly one of two boxes.
How to use XOR with IF#
TRUE and FALSE are fine for checking, but a label is easier to read. Put XOR in the test of IF:
=IF(XOR(B2="Yes",C2="Yes"),"Check","OK")Now the column shows Check for orders 1002, 1004 and 1006, and OK for the rest. IF returns its second argument when the test is TRUE and its third when the test is FALSE. If you want to filter or count the problem rows later, a clear word like Check is easier to work with than TRUE. For more on combining logic with IF, see IF with OR and IF with AND.
XOR with numbers#
The tests inside XOR can be any comparison, not only text. Say a bonus applies to a rep who beat the sales target or the new-customer target, but not both, because hitting both earns a different, bigger award:
=XOR(B2>=50000,C2>=10)If B2 is 62000 and C2 is 8, only the first test is TRUE, so XOR returns TRUE. If B2 is 62000 and C2 is 12, both are TRUE, so XOR returns FALSE. To test a value inside a range rather than above a line, see IF between two numbers.
The trap: XOR with three or more conditions#
With three or more conditions, XOR returns TRUE when an odd number of them are TRUE, not when exactly one is. That surprises many people:
| Tests that are TRUE | XOR result |
|---|---|
| 0 of 3 | FALSE |
| 1 of 3 | TRUE |
| 2 of 3 | FALSE |
| 3 of 3 | TRUE |
So =XOR(TRUE,TRUE,TRUE) returns TRUE. If you need "exactly one of these three cells says Yes", count the matches instead:
=COUNTIF(B2:D2,"Yes")=1This returns TRUE only when one cell in B2:D2 is Yes. For tests that aren't simple matches, add them up. In Excel, TRUE counts as 1 and FALSE as 0 when you add them:
=(B2>100)+(C2>100)+(D2>100)=1XOR vs OR and other ways to write it#
Use OR when "at least one" is the rule, and XOR when "one but not both" is the rule. The OR function guide covers OR in detail, and the article on AND vs OR compares those two.
For two conditions, you can also write XOR without the function. Two tests are "exclusive" when their results differ, so <> (not equal to) does the same job:
=(B2="Yes")<>(C2="Yes")This works in every version of Excel, which helps if a file must open in Excel 2010. XOR is easier to read, though, so use it when you can.
To count the mismatched orders in one cell, count each kind of mismatch and add them:
=COUNTIFS(B2:B7,"Yes",C2:C7,"No")+COUNTIFS(B2:B7,"No",C2:C7,"Yes")That gives 2 + 1 = 3.
Common XOR mistakes#
These are the problems that come up most:
- Expecting "exactly one" with three or more tests. XOR checks for an odd number. Use COUNTIF or added tests instead.
- Forgetting quotes around text.
B2=Yesgives #NAME?. WriteB2="Yes". - Using XOR where OR is meant. If both conditions being TRUE should also pass, XOR gives the wrong answer for those rows.
- Old Excel versions. XOR returns #NAME? in Excel 2010 and earlier. Use the
<>version there.
Where XOR helps in real sheets#
XOR is not an everyday function, but it shines in data checks. Three common uses:
- Mismatch flags. Two columns that should agree, like Paid and Shipped.
=XOR(B2<>"",C2<>"")also flags rows where only one of two cells is filled in, such as a start date with no end date. - Either-or rules. A discount for members or for coupon holders, but not both.
- Reviewer disagreement. Two approvers who should reach the same decision.
In a test, the question rarely names XOR. Look for wording such as "one or the other but not both" or "exactly one of the two". For two conditions, that is XOR.
Practise it#
XOR is easy once AND, OR and NOT feel natural. Practise AND, OR and NOT in a live spreadsheet: you type each logical test and the lesson checks it instantly. Then try the exercise on this page and flag the order that was paid but not shipped.
Try it yourself
This is a live spreadsheet. Type the formula in the green cell and press Enter.
Order 1002 is paid but not shipped. In D3, write a formula that shows Check when exactly one of B3 and C3 is Yes, and OK otherwise. Use IF with XOR.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Status | ||||
| 2 | Yes | ||||
| 3 | No | ||||
| 4 | No | ||||
| 5 | Yes | ||||
| 6 | Yes | ||||
| 7 | No | ||||
| 8 | |||||
| 9 | |||||
| 10 |
Tip: Inside IF, write XOR(B3="Yes",C3="Yes") as the test, then "Check" and "OK" as the two results.
Practise this in a lesson
Frequently asked questions
What does XOR do in Excel?
XOR checks two or more conditions and returns TRUE when an odd number of them are TRUE. With two conditions, that means exactly one is TRUE. If both or neither are TRUE, it returns FALSE.
What is the difference between OR and XOR in Excel?
OR returns TRUE when at least one condition is TRUE, including when both are. XOR returns FALSE when both are TRUE. The two only differ in that one case.
Which Excel versions have XOR?
XOR is available in Excel 2013 and later, including Excel 2016, 2019, 2021, Microsoft 365 and Excel for the web. In Excel 2010 or older it returns #NAME?.
How do I check that exactly one of three cells is Yes?
Don't use XOR, because XOR is also TRUE when all three are Yes. Count the matches instead: =COUNTIF(B2:D2,"Yes")=1 returns TRUE only when exactly one cell says Yes.
Can I use XOR with IF?
Yes. Put XOR in the test of IF: =IF(XOR(B2="Yes",C2="Yes"),"Check","OK"). IF then shows Check when exactly one condition is TRUE and OK otherwise.