XOR function
The XOR function in Excel is a logical function that returns TRUE if an odd number of the arguments are TRUE, and FALSE if an even number of the arguments are TRUE. Essentially, the XOR (Exclusive OR) function checks if the number of TRUE values in the arguments is odd.
This function is particularly useful when you need to test multiple conditions and return TRUE only when exactly one of the conditions is TRUE, or when an odd number of conditions are TRUE.
Syntax:
=XOR(logical1, logical2, ...)
- logical1, logical2, …: These are the conditions or logical values you want to evaluate. You can provide multiple logical conditions (up to 254 arguments).
Example 1: Basic Usage
If you have two conditions in cells A1 and B1:
A1isTRUEB1isFALSE
You can use the XOR function to check whether exactly one of the conditions is TRUE:
=XOR(A1, B1)
- Since one condition is
TRUEand the other isFALSE, the function will returnTRUE.
Example 2: Multiple Conditions
If you have three conditions in cells A1, B1, and C1:
A1isTRUEB1isTRUEC1isFALSE
You can use:
=XOR(A1, B1, C1)
- Since two conditions are
TRUEand one isFALSE, the function will returnFALSE(because an even number of conditions areTRUE).
Example 3: Odd vs. Even Number of TRUE Values
If you have four conditions in cells A1, B1, C1, and D1:
A1isTRUEB1isTRUEC1isTRUED1isTRUE
You can use:
=XOR(A1, B1, C1, D1)
- Since four conditions are
TRUE(an even number), the function will returnFALSE.
Example 4: Using XOR with Direct TRUE/FALSE
You can also use XOR with direct logical values. For example:
=XOR(TRUE, FALSE, TRUE)
- The result is
TRUEbecause two arguments areTRUE(odd number ofTRUEs).
Benefits:
- Exclusive testing:
XORhelps in scenarios where you need to confirm that exactly one condition is true, or an odd number of conditions. - Simplifies complex logic: It provides an easier way to evaluate conditions when traditional methods with
ANDorORwould require more nested logic.
Summary:
XORreturnsTRUEwhen an odd number of conditions areTRUE.XORreturnsFALSEwhen an even number of conditions areTRUE.