Function XOR in Excel

Reading time: 2 minutes

What is the purpose of the XOR function in logic?

In logic, there are two ways to specify an OR

  1. Inclusive OR

    This is when any argument of the function returns TRUE. You can have only one or more than one TRUE, the function will return TRUE.
    This is the OR function in Excel

  2. Exclusive OR

    In this situation, only one argument can return TRUE, but not both. This is the XOR function.

When to use the XOR function

The best way to explain is to present this function in a comprehensive example. We want to buy a new computer but (of course) we have a small budget. So we will consider 2 elements of the computer: the size of the hard-drive and the RAM.

In our example below we are looking for a computer with one of these elements:

  • At least 500MB Hard Drive
  • At least 6GB of RAM

If a computer has one of these elements, we consider it but if it has both, we don’t reject it (as it would be out of our budget)

Test with the OR function

Let’s make a test with the OR function.

If you use a Table, the formula would be:

=OR([@[Hard-Drive]]>=500,[@RAM]>=6)

If you prefer to use cell references, the formula would be:

=OR(B2>=500,C2>=6)

As you can see, with a function OR, most of the computers can be selected. This is because with OR, if one or more tests is TRUE, the function return TRUE.

For instance, computer 3 has a hard-drive greater than 500 and also the RAM greater than 6. The 2 tests are TRUE, so the function OR returns TRUE.

Test with the XOR function

Now, if we change the formula with the function XOR, the result is different

=XOR([@[Hard-Drive]]>=500,[@RAM]>=6)

Now, only 2 computers match the test.

  • Computer 1 has a hard drive of 512 (test TRUE) and RAM of 4 (test FALSE).
    • Only one test is TRUE so the OR function returns TRUE
  • Computer 3 has a hard drive of 512 (test TRUE) and RAM of 8 (test TRUE)
    • Both tests are TRUE, so the XOR function returns FALSE

Integrate the test in an IF function

To avoid leaving the result TRUE or FALSE in your cells, you can integrate the test in an IF function like this:

=IF([@[Result XOR]],”Consider”,””)

You can find more examples and explanations of how to use the IF function in this article.

Practice with exercises

Practice logical tests directly in the grid below.

Logical Tests Exercise - Check an employee's details (TRUE/FALSE)

Write 7 independent logical tests (TRUE/FALSE) on one employee's record: empty cells, text comparisons, thresholds and LEFT/RIGHT — 7 guided steps, no fill-down.

Write the logical test in cell G2

1 / 7

In G2, how do you write the logical test that checks whether the email is missing?

Logical tests — Q1 · 683

Write the logical test in cell G3

2 / 7

In G3, how do you write the logical test that checks whether the employee on row 2 is a man? The Gender column (B) contains "Male" or "Female".

Logical tests — Q2 · 684

Write the logical test in cell G4

3 / 7

In G4, how do you write the logical test that checks whether the employee on row 2 is different from "Male"?

Logical tests — Q3 · 685

Write the logical test in cell G5

4 / 7

In G5, how do you write the logical test that checks whether the salary on row 2 is below 2000?

Logical tests — Q4 · 686

Write the logical test in cell G6

5 / 7

In G6, how do you write the logical test that checks whether the postal code on row 2 is equal to 69001?

Logical tests — Q5 · 687

Write the logical test in cell G7

6 / 7

In G7, how do you write the logical test that checks whether the postal code on row 2 starts with 69?

Logical tests — Q6 · 688

Write the logical test in cell G8

7 / 7

In G8, how do you write the logical test that checks whether the email on row 2 ends with "@xyz.com"?

Logical tests — Q7 · 689

Your score is

0%

Related articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Function XOR in Excel

Reading time: 2 minutes

What is the purpose of the XOR function in logic?

In logic, there are two ways to specify an OR

  1. Inclusive OR

    This is when any argument of the function returns TRUE. You can have only one or more than one TRUE, the function will return TRUE.
    This is the OR function in Excel

  2. Exclusive OR

    In this situation, only one argument can return TRUE, but not both. This is the XOR function.

When to use the XOR function

The best way to explain is to present this function in a comprehensive example. We want to buy a new computer but (of course) we have a small budget. So we will consider 2 elements of the computer: the size of the hard-drive and the RAM.

In our example below we are looking for a computer with one of these elements:

  • At least 500MB Hard Drive
  • At least 6GB of RAM

If a computer has one of these elements, we consider it but if it has both, we don’t reject it (as it would be out of our budget)

Test with the OR function

Let’s make a test with the OR function.

If you use a Table, the formula would be:

=OR([@[Hard-Drive]]>=500,[@RAM]>=6)

If you prefer to use cell references, the formula would be:

=OR(B2>=500,C2>=6)

As you can see, with a function OR, most of the computers can be selected. This is because with OR, if one or more tests is TRUE, the function return TRUE.

For instance, computer 3 has a hard-drive greater than 500 and also the RAM greater than 6. The 2 tests are TRUE, so the function OR returns TRUE.

Test with the XOR function

Now, if we change the formula with the function XOR, the result is different

=XOR([@[Hard-Drive]]>=500,[@RAM]>=6)

Now, only 2 computers match the test.

  • Computer 1 has a hard drive of 512 (test TRUE) and RAM of 4 (test FALSE).
    • Only one test is TRUE so the OR function returns TRUE
  • Computer 3 has a hard drive of 512 (test TRUE) and RAM of 8 (test TRUE)
    • Both tests are TRUE, so the XOR function returns FALSE

Integrate the test in an IF function

To avoid leaving the result TRUE or FALSE in your cells, you can integrate the test in an IF function like this:

=IF([@[Result XOR]],”Consider”,””)

You can find more examples and explanations of how to use the IF function in this article.

Practice with exercises

Practice logical tests directly in the grid below.

Logical Tests Exercise - Check an employee's details (TRUE/FALSE)

Write 7 independent logical tests (TRUE/FALSE) on one employee's record: empty cells, text comparisons, thresholds and LEFT/RIGHT — 7 guided steps, no fill-down.

Write the logical test in cell G2

1 / 7

In G2, how do you write the logical test that checks whether the email is missing?

Logical tests — Q1 · 683

Write the logical test in cell G3

2 / 7

In G3, how do you write the logical test that checks whether the employee on row 2 is a man? The Gender column (B) contains "Male" or "Female".

Logical tests — Q2 · 684

Write the logical test in cell G4

3 / 7

In G4, how do you write the logical test that checks whether the employee on row 2 is different from "Male"?

Logical tests — Q3 · 685

Write the logical test in cell G5

4 / 7

In G5, how do you write the logical test that checks whether the salary on row 2 is below 2000?

Logical tests — Q4 · 686

Write the logical test in cell G6

5 / 7

In G6, how do you write the logical test that checks whether the postal code on row 2 is equal to 69001?

Logical tests — Q5 · 687

Write the logical test in cell G7

6 / 7

In G7, how do you write the logical test that checks whether the postal code on row 2 starts with 69?

Logical tests — Q6 · 688

Write the logical test in cell G8

7 / 7

In G8, how do you write the logical test that checks whether the email on row 2 ends with "@xyz.com"?

Logical tests — Q7 · 689

Your score is

0%

Related articles

Leave a Reply

Your email address will not be published. Required fields are marked *