Google Sheets XOR Function: Step-by-Step Guide
In this article
The XOR function in Google Sheets returns TRUE if an odd number of the supplied logical expressions are TRUE, and FALSE if an even number are TRUE. In plain terms, it is an "exclusive OR": it flags a row when exactly one of two conditions is met, but not when both or neither are. To use it, type =XOR(logical_expression1, [logical_expression2, ...]) into a cell, replacing the arguments with cell references or comparisons such as A2>10. That single line is the whole answer; the rest of this guide covers how to build it reliably, what it does with more than two conditions, and the mistakes that make it return the wrong result.
What You'll Need
- A Google account with access to Google Sheets (the function works in the browser version and the mobile apps).
- A spreadsheet with at least one column of values you want to test, or a blank sheet if you are experimenting.
- Basic familiarity with entering formulas: starting with
=and pressing Enter. - No add-ons or scripts are required; XOR is a built-in function.
Step-by-Step
- Open your spreadsheet. Go to Google Sheets in your browser or open the Google Sheets app on your phone or tablet. Menu labels can differ slightly by version, device and region, so if a label below does not match exactly, look for the closest equivalent.
- Pick an empty cell for the result. Click a cell to the right of your data, for example
C2if your values are in columns A and B. This keeps the formula next to the row it evaluates. - Start the formula with an equals sign. Type
=XOR(. Google Sheets will show a function hint with the expected arguments. Do not type a space between the equals sign and the function name. - Enter the first logical expression. This can be a comparison such as
A2>10, a cell containing TRUE or FALSE, or a number (where 0 counts as FALSE and any other number counts as TRUE). For example:=XOR(A2>10. - Add a comma and the second expression. Type
, B2="Yes"so the formula reads=XOR(A2>10, B2="Yes"). Text comparisons need quotation marks around the text; numbers do not. - Close the parenthesis and press Enter. The cell shows TRUE when exactly one of the two conditions is met, and FALSE when both are met or neither is met.
- Copy the formula down the column. Drag the small fill handle at the bottom-right corner of the cell, or copy the cell and paste it into the rows below. Relative references adjust automatically, so each row is evaluated on its own values.
- Test the result against your data. Pick a row where you know the expected answer and compare. If it does not match, check for text stored as numbers (for example a number formatted as text) or extra spaces in text values, both of which change the comparison result.
- Add more conditions if needed. XOR accepts more than two arguments:
=XOR(A2>10, B2="Yes", C2<>"")returns TRUE when an odd number of the three conditions are true (one or three), and FALSE when an even number are true (zero or two). This is the part most people get wrong, so decide in advance whether you want "exactly one" or "an odd number". - Wrap it in IF for readable output. To show words instead of TRUE/FALSE, use
=IF(XOR(A2>10, B2="Yes"), "Flag", "OK"). The XOR result becomes the condition, and IF turns it into a label.
Common Mistakes
- Expecting "exactly one" with three or more arguments. XOR is true for any odd count of TRUE values, so with three conditions it returns TRUE when all three are true. If you need exactly one, use
=COUNTIF(range, TRUE)=1or a combination of AND and NOT instead. - Forgetting quotation marks around text.
B2=Yeswithout quotes is read as a named range or an error, not the word "Yes". WriteB2="Yes". - Comparing numbers stored as text. A value that looks like 10 but is stored as text will not behave like the number 10 in
A2>10. Convert the column to numbers (Format > Number) or use VALUE() before comparing. - Leaving trailing spaces in text. "Yes " and "Yes" are different to Sheets. Trim imported data or use TRIM() in the comparison.
- Using XOR where OR was meant. OR returns TRUE when at least one condition is true, including when both are true. XOR excludes the both-true case. Pick the one that matches your rule.
- Passing ranges directly. XOR expects individual logical expressions, not a whole range in most cases. If you need to test a range, combine it with functions such as COUNTIF or SUMPRODUCT.
Tips
- Use cell references rather than hard-coded values so the formula updates when your data changes.
- Name your conditions in a helper column first (for example a column that returns TRUE/FALSE for each rule), then feed those cells into XOR. It makes complex sheets far easier to audit.
- Remember that 0 is FALSE and any non-zero number is TRUE, which lets you use XOR on numeric flags.
- Wrap XOR in IF when the output is for other people; TRUE and FALSE are fine for you but labels are clearer in a shared sheet.
- Test with a small set of known rows before filling the formula down hundreds of rows.
Troubleshooting
- Formula returns #N/A or #VALUE! One argument is not a logical expression. Check for stray text without quotes, an empty required reference, or a range passed where a single value is expected.
- Result is always FALSE. Both conditions may be true in every row, or neither is being met because of a text/number mismatch. Test each condition separately in its own cell to see which one is failing.
- Result is always TRUE. One condition may be true in every row, or a comparison is accidentally always true (for example comparing a cell to itself).
- Copied formula gives wrong answers. Check whether you used absolute references ($A$2) where relative ones were needed, or vice versa. Press Ctrl+Z (Cmd+Z on Mac) to undo and re-copy.
- Text looks identical but compares as different. Use TRIM() and check for non-printing characters; imported data often carries hidden spaces.
- Nothing works and the sheet is slow or odd. Reload the browser tab, sign out and back in, and check that you are editing the file you think you are. If the problem persists, try a fresh blank sheet to confirm the formula itself is correct.
Frequently Asked Questions
What does XOR return with two conditions?
TRUE when exactly one condition is true, and FALSE when both are true or both are false. That is the classic exclusive-or behaviour.
Can XOR take more than two arguments?
Yes. It accepts additional logical expressions and returns TRUE when an odd number of them are true. With three arguments, that means one or three true values.
How is XOR different from OR?
OR returns TRUE if at least one condition is true, including when both are true. XOR returns FALSE when both are true, so it excludes the overlap.
Does XOR work in the Google Sheets mobile app?
Yes, the function is part of Sheets itself and works the same on mobile, though typing long formulas is easier on a computer.
Can I use XOR to count rows?
Not directly. XOR returns a single TRUE or FALSE. To count rows matching an exclusive condition, combine COUNTIF or SUMPRODUCT with your logic, or add a helper column of XOR results and count the TRUE values.
Why does XOR return TRUE when all three of my conditions are true?
Because three is an odd number. If you need exactly one true condition, XOR is the wrong tool; use a COUNTIF-based check instead.