The XOR function in Google Sheets performs an exclusive OR operation. But what exactly does “exclusive OR” (often abbreviated as XOR or EOR) mean?
In logical terms, the XOR function differs from the standard OR function. While OR returns TRUE if any one of the conditions is TRUE, XOR only returns TRUE when an odd number of conditions are evaluated to TRUE.
This feature is what makes XOR “exclusive.” Even if the majority of conditions are TRUE, XOR may still return FALSE if the count of TRUE values is even.
To clarify, here’s how XOR works with examples:
- Example 1: If there are 10 conditions, and only one evaluates to
TRUE, then XOR will returnTRUEbecause the count is odd. - Example 2: If 8 conditions evaluate to
TRUEand 2 evaluate toFALSE, XOR will returnFALSEbecause the count ofTRUEvalues is even.
XOR Function vs. OR Function: Key Differences
You might wonder when the XOR function is useful compared to the OR function. The key difference is that XOR returns TRUE only when exactly one of the conditions is TRUE in a two-condition scenario, unlike OR, which returns TRUE if either or both conditions are TRUE.
For example:
OR(A1, B1)returnsTRUEif either or bothA1andB1areTRUE.XOR(A1, B1)returnsTRUEonly if one ofA1orB1isTRUE(but not both).
XOR Function: Syntax and Arguments
XOR(logical_expression1, [logical_expression2, …])
- logical_expression1: An expression or a cell reference containing a logical value, such as
TRUEorFALSE, or an expression that evaluates to a logical value. - logical_expression2, …: Additional logical expressions to test.
XOR Formula Examples
Let’s look at some practical examples to understand XOR in Google Sheets:
Example 1: Basic Boolean Test
- In cells A1:A10, enter
0s (representingFALSEvalues). - Use the following formula:
=XOR(A1:A10)Since all values areFALSE, this formula will returnFALSE. - Now change the value in A10 to
1(representingTRUE). The formula will now returnTRUEbecause there is oneTRUEvalue, which is an odd count. - If you change another cell (say A9) to
1, the formula will returnFALSEbecause there are now twoTRUEvalues, which is an even count.
In Google Sheets, 0 is interpreted as FALSE, and 1 as TRUE in Boolean logic.
Example 2: Choosing Based on Budget (Practical Scenario)
Suppose you want to buy a smartphone, and your budget is <$1500. You’re comparing prices of two models, with Product 1’s price in cell A1 and Product 2’s price in cell B1.
Scenario:
- If both phones are either within your budget or over your budget, you’ll flip a coin to decide which one to buy or consider increasing your budget.
- If only one phone is within budget, you’ll choose the affordable one.
Use this combined formula with the XOR and IF functions to make a decision:
=IF(XOR(A1 <= 1500, B1 <= 1500), MIN(A1, B1), "Flip a coin")
- This formula returns the price of the cheaper phone if only one of the phones is within budget (since XOR returns
TRUEif only one condition isTRUE). - If both phones are either within the budget or both are outside the budget, the formula suggests flipping a coin.
Conclusion
The XOR function is a versatile tool for situations where you need to evaluate exclusive conditions. It’s particularly useful in scenarios where only an odd count of conditions should trigger a result, making it a unique choice for Boolean logic in Google Sheets.
That’s all! With XOR, you can add more precision to your decision-making processes in spreadsheets.




















