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], ...)| Argument | What it means | |
|---|---|---|
logical1 | Required | The first condition or range of logical values. |
logical2, ... | Optional | More 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
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Employee | Morning | Evening | |
| 2 | Gita | Yes | No | TRUE |
| 3 | Hugo | Yes | Yes | |
| 4 | Ivan | No | No |
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
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Order | Promo code | Loyalty discount | |
| 2 | SO-901 | TRUE | TRUE | FALSE |
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
| A | |
|---|---|
| 1 | TRUE |
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.
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
#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 asa<>b, which also works in versions before Excel 2013. - For "exactly one of many" use
SUM(--(range="Yes"))=1instead 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.
| Language | Function name |
|---|---|
| Danish | XELLER |
| Dutch | EX.OF |
| Finnish | EHDOTON.TAI |
| French | OUX |
| German | XODER |
| Hungarian | XVAGY |
| Norwegian (Bokmål) | EKSKLUSIVELLER |
| Portuguese (Portugal) | XOU |
| Russian | ИСКЛИЛИ |
| Spanish | XO |
| Swedish | XELLER |
| Turkish | ÖZELVEYA |