How to Use the XOR Function in Google Sheets

Published on

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 return TRUE because the count is odd.
  • Example 2: If 8 conditions evaluate to TRUE and 2 evaluate to FALSE, XOR will return FALSE because the count of TRUE values 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) returns TRUE if either or both A1 and B1 are TRUE.
  • XOR(A1, B1) returns TRUE only if one of A1 or B1 is TRUE (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 TRUE or FALSE, 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

  1. In cells A1:A10, enter 0s (representing FALSE values).
  2. Use the following formula: =XOR(A1:A10) Since all values are FALSE, this formula will return FALSE.
  3. Now change the value in A10 to 1 (representing TRUE). The formula will now return TRUE because there is one TRUE value, which is an odd count.
  4. If you change another cell (say A9) to 1, the formula will return FALSE because there are now two TRUE values, 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 TRUE if only one condition is TRUE).
  • 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.

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Expert Prashanth KV is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Google Sheets: Get the Last Row with Any Data Across Multiple Columns

It’s common to have several empty rows at the bottom of a Google Sheet,...

How to Calculate Digital Root in Google Sheets

The digital root is the single-digit value you get by repeatedly summing the digits...

How to Build an Advanced Book Tracker in Google Sheets: Formulas Explained

If you're tired of forgetting what you've read, which books you rated 5 stars,...

Google Sheets Reading List Tracker Template (Free Download)

Looking for a smarter, more visual way to manage your reading goals? This Google...

More like this

Google Sheets: Get the Last Row with Any Data Across Multiple Columns

It’s common to have several empty rows at the bottom of a Google Sheet,...

How to Calculate Digital Root in Google Sheets

The digital root is the single-digit value you get by repeatedly summing the digits...

How to Build an Advanced Book Tracker in Google Sheets: Formulas Explained

If you're tired of forgetting what you've read, which books you rated 5 stars,...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.