Skip to content

XOR

Returns TRUE when an odd number of your conditions are true. With two conditions, it means one or the other but not both.

Syntax

=XOR(, [logical2], ...)

Logical

Excel 2013 and later, including Microsoft 365, Excel 2024, 2021, 2019 and 2016, Excel for the web and the mobile apps. Not available in Excel 2010 or earlier.

Try it

Edit the formula in D2 or change the inputs. The sheet recalculates as you type.

D2
A
B
C
D
1
Request
Approver 1
Approver 2
Split decision?
2
R-01
Yes
No
TRUE
3
4

D2 =XOR(B2="Yes",C2="Yes") returns TRUE

How XOR works

XOR is the "exclusive or". With two conditions it returns TRUE when exactly one of them is true, and FALSE when both are true or both are false. =XOR(B2="Yes", C2="Yes") is TRUE if exactly one of the two approvers said yes.

Compare that with OR, which is TRUE when at least one is true, including both. XOR leaves out the "both" case.

The rule for more than two conditions

XOR doesn't mean "exactly one" once you give it three or more arguments. It means an odd number:

  • one true, two false: TRUE
  • two true, one false: FALSE
  • three true: TRUE
  • none true: FALSE

If you want "exactly one of three" use a count instead: =(A2="x")+(B2="x")+(C2="x")=1, or =COUNTIF(A2:C2,"x")=1.

The arguments

Each argument is a condition: a comparison such as B2>0, a cell or formula that returns TRUE or FALSE, or a range of such values. A number counts as TRUE unless it is zero. Text and empty cells inside a range are ignored, and if nothing logical remains, XOR returns #VALUE!. If any argument is an error, XOR returns that error.

XOR can also take a range: =XOR(B2:D2>0) is TRUE if an odd number of the three cells are above zero.

When XOR is useful

  • Mismatch checks. =XOR(B2="Yes", C2="Yes") flags rows where two reviewers disagree.
  • Either-or rules. A customer can be in the loyalty scheme or the trade scheme, but not both: =XOR(D2="Loyalty", D2="Trade") on a row that shows both flags.
  • Toggles. XOR of a cell with TRUE flips it, the same as NOT.
  • Reconciliation. When one list says an item exists and another says it doesn't, =XOR(ISNUMBER(MATCH(A2,List1,0)), ISNUMBER(MATCH(A2,List2,0))) finds the items that are in only one list.

XOR is not the same as OR

The easiest mistake is using OR when you need "one but not both". OR says an applicant with both qualifications is fine. XOR says that applicant is flagged. If a rule says "one or the other", check whether it also allows both. If it does, use OR.

Writing it without XOR

You can express XOR with other functions, which is useful in Excel 2010 or earlier: =AND(OR(a, b), NOT(AND(a, b))) is the same as =XOR(a, b). Or use =(a)<>(b) when a and b are logical values, since TRUE and FALSE compare as different.

Using it in IF

XOR gives a logical result, so wrap it in IF to return words: =IF(XOR(B2="Yes", C2="Yes"), "Escalate", "OK").

Arguments

logical1
The first condition, such as B2="Yes", or a range of TRUE/FALSE values.
logical2, ...optional
More conditions, up to 255 in total. XOR returns TRUE if an odd number of them are true, and FALSE if an even number (including none) are true. Text and empty cells inside a range are ignored. If no argument holds a logical value, XOR returns #VALUE!.

Examples

Each example is a live sheet. Change the inputs or the formula and watch the result.

Example 1

One approver, but not both

D2 =XOR(B2="Yes",C2="Yes")

Result: TRUE

Exactly one approver said Yes, so XOR returns TRUE. If both had said Yes, or both No, the result would be FALSE.

D2
A
B
C
D
1
Request
Approver 1
Approver 2
Split decision?
2
R-01
Yes
No
TRUE
3
4

D2 =XOR(B2="Yes",C2="Yes") returns TRUE

Example 2

Both true gives FALSE, unlike OR

D2 =XOR(B2="Yes",C2="Yes")

Result: FALSE

Two true conditions is an even number, so XOR returns FALSE. OR would return TRUE for the same row.

D2
A
B
C
D
1
Request
Approver 1
Approver 2
Split decision?
2
R-02
Yes
Yes
FALSE
3
4

D2 =XOR(B2="Yes",C2="Yes") returns FALSE

Example 3

Three conditions: an odd number is TRUE

D2 =XOR(A2>0,B2>0,C2>0)

Result: FALSE

Two of the three conditions are true (A2 and C2), which is even, so the result is FALSE. XOR with three arguments is not "exactly one".

D2
A
B
C
D
E
1
Check A
Check B
Check C
XOR
2
5
0
8
FALSE
3
4

D2 =XOR(A2>0,B2>0,C2>0) returns FALSE

Example 4

Items that are in only one of two lists

E2 =XOR(ISNUMBER(MATCH(D2,A2:A4,0)),ISNUMBER(MATCH(D2,B2:B3,0)))

Result: TRUE

INV-2 is in the sent list but not in the payments list, so one test is true and one false. XOR returns TRUE: the invoice is in only one list.

E2
A
B
C
D
E
F
1
Invoices sent
Payments received
Item
In only one?
2
INV-1
INV-1
INV-2
TRUE
3
INV-2
INV-3
4
INV-3
5
6

E2 =XOR(ISNUMBER(MATCH(D2,A2:A4,0)),ISNUMBER(MATCH(D2,B2:B3,0))) returns TRUE

Your turn.

Solve it in the sheet. Every answer is checked, with hints if you need them.

Task 1 of 2

In D2, return TRUE when exactly one of the two approvers said Yes, and FALSE otherwise. Fill down to D7.

Answer in D2, then it fills down to D7.

D2
A
B
C
D
E
F
1
Request
Approver 1
Approver 2
Split decision?
Action
2
R-01
Yes
No
3
R-02
Yes
Yes
4
R-03
No
No
5
R-04
No
Yes
6
R-05
Yes
No
7
R-06
No
No
8

Common mistakes

  • With more than two conditions, XOR is TRUE for an odd number of true conditions, not for exactly one. Three true conditions also give TRUE.
  • XOR isn't the same as OR. OR is TRUE when both conditions are true; XOR is FALSE.
  • XOR isn't available in Excel 2010 or earlier, where it returns #NAME?.
  • Text and empty cells inside a range are ignored, and if nothing logical remains, XOR returns #VALUE!.
  • When the rule really means "exactly one", say so with a count: COUNTIF(range, "Yes")=1. It reads more clearly than XOR for more than two items.

Questions people ask

What does XOR mean in Excel?

Exclusive or. With two conditions, XOR is TRUE when exactly one is true and FALSE when both are true or both are false.

What is the difference between XOR and OR?

OR is TRUE when at least one condition is true, including both. XOR is TRUE only when an odd number are true, so with two conditions it is FALSE when both are true.

How do I check that exactly one of three conditions is true?

XOR won't do it. Count them instead: `=COUNTIF(A2:C2, "Yes")=1`, or add the tests: `=(A2="Yes")+(B2="Yes")+(C2="Yes")=1`.

How do I write XOR in Excel 2010?

Use `=AND(OR(a, b), NOT(AND(a, b)))`, or, for two logical values, `=(a)<>(b)`.

Learn XOR in a real sheet.

Tracks take you from the basics to modelling, one graded exercise at a time.