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 =XOR(B2="Yes",C2="Yes") returns TRUE
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], ...)
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 =XOR(B2="Yes",C2="Yes") returns TRUE
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.
XOR doesn't mean "exactly one" once you give it three or more arguments. It means an odd number:
If you want "exactly one of three" use a count instead: =(A2="x")+(B2="x")+(C2="x")=1, or =COUNTIF(A2:C2,"x")=1.
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.
=XOR(B2="Yes", C2="Yes") flags rows where two reviewers disagree.=XOR(D2="Loyalty", D2="Trade") on a row that shows both flags.=XOR(ISNUMBER(MATCH(A2,List1,0)), ISNUMBER(MATCH(A2,List2,0))) finds the items that are in only one list.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.
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.
XOR gives a logical result, so wrap it in IF to return words: =IF(XOR(B2="Yes", C2="Yes"), "Escalate", "OK").
B2="Yes", or a range of TRUE/FALSE values.#VALUE!.Each example is a live sheet. Change the inputs or the formula and watch the result.
Example 1
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 =XOR(B2="Yes",C2="Yes") returns TRUE
Example 2
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 =XOR(B2="Yes",C2="Yes") returns FALSE
Example 3
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 =XOR(A2>0,B2>0,C2>0) returns FALSE
Example 4
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 =XOR(ISNUMBER(MATCH(D2,A2:A4,0)),ISNUMBER(MATCH(D2,B2:B3,0))) returns TRUE
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.
#NAME?.#VALUE!.COUNTIF(range, "Yes")=1. It reads more clearly than XOR for more than two items.Exclusive or. With two conditions, XOR is TRUE when exactly one is true and FALSE when both are true or both are false.
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.
XOR won't do it. Count them instead: `=COUNTIF(A2:C2, "Yes")=1`, or add the tests: `=(A2="Yes")+(B2="Yes")+(C2="Yes")=1`.
Use `=AND(OR(a, b), NOT(AND(a, b)))`, or, for two logical values, `=(a)<>(b)`.
Tracks take you from the basics to modelling, one graded exercise at a time.