Logical function

XOR function

Exclusive OR: returns TRUE when an odd number of the conditions are TRUE. With two conditions it means "exactly one, not both".

Available in Excel 2013 and later, Microsoft 365, Excel for the web

Excel 2013 and laterWorks in Google Sheets

Syntax

XOR(logical1, [logical2], ...)
ArgumentWhat it means
logical1RequiredThe first condition or range of logical values.
logical2, ...OptionalMore conditions, up to 254 more.

Returns: TRUE if the number of TRUE conditions is odd, FALSE if it is even (including zero).

How XOR works

XOR ("exclusive or") answers a question that OR cannot: is exactly one of these two things true? OR returns TRUE when both conditions hold; XOR returns FALSE in that case. It fits rules such as "a staff member must choose either the morning or the evening shift, not both and not neither", or checking that an order has a discount code or a loyalty discount, but not both stacked.

With more than two conditions XOR counts how many are TRUE and returns TRUE when that count is odd (1, 3, 5, ...). That is mathematically correct but often surprising: three TRUE conditions give TRUE. If what you really want is "exactly one of many", count the TRUEs instead, e.g. =SUM(--(B2:D2="Yes"))=1.

Examples

1Exactly one shift chosen

D2fx=XOR(B2="Yes", C2="Yes")
ABCD
1EmployeeMorningEvening
2GitaYesNoTRUE
3HugoYesYes
4IvanNoNo

Result: TRUE

Gita picked only the morning shift: one TRUE, so XOR is TRUE. Hugo picked both (two TRUEs, even) and Ivan neither (zero), so both return FALSE — exactly the people the planner must contact.

2Both discounts applied

D2fx=XOR(B2, C2)
ABCD
1OrderPromo codeLoyalty discount
2SO-901TRUETRUEFALSE

Result: FALSE

Both discounts are TRUE, which is an even count, so XOR returns FALSE: this order breaks the "one discount only" rule. OR would have returned TRUE here.

3Three TRUE conditions

A1fx=XOR(TRUE, TRUE, TRUE)
A
1TRUE

Result: TRUE

Three is odd, so the result is TRUE. This is why XOR is not a test for "exactly one" when you have more than two conditions.

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 15 KB

Common errors and how to fix them

ErrorWhy it happensFix
#VALUE!No logical values were found in the arguments.Use comparisons such as B2="Yes" rather than raw text.

Tips

  • With exactly two conditions, XOR(a, b) is the same as a<>b, which also works in versions before Excel 2013.
  • For "exactly one of many" use SUM(--(range="Yes"))=1 instead of XOR.

Google Sheets

XOR also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.

XOR in other languages

In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.

LanguageFunction name
DanishXELLER
DutchEX.OF
FinnishEHDOTON.TAI
FrenchOUX
GermanXODER
HungarianXVAGY
Norwegian (Bokmål)EKSKLUSIVELLER
Portuguese (Portugal)XOU
RussianИСКЛИЛИ
SpanishXO
SwedishXELLER
TurkishÖZELVEYA

Recipes that use XOR