# XOR
URL: https://docs.valsight.ai/xor/
Description: Connects two inputs with the logical 'exclusive or' XOR and returns true (1) if exactly one of the input values is true and false (0) otherwise.
**Category:** [Logical functions](/logical-functions/)

## Overview

The **XOR** function **connects two inputs with the logical 'exclusive or' XOR** and returns true (1) if exactly one of the input values is true and false (0) otherwise.

Use this function when you need a 1/0 flag that becomes true only if exactly one of two inputs is true.

## Syntax

`XOR('Node1', 'Node2')`

## Parameters

| Parameter | Description                                                                         | Type           | Required |
| --------- | ----------------------------------------------------------------------------------- | -------------- | -------- |
| **Node1** | First input node, specified using the node name in single quotes (e.g. `'Profit'`). | Node reference | Yes      |
| **Node2** | Second input node.                                                                  | Node reference | Yes      |

## Watch out

* Both input nodes must have the same dimensionality; otherwise rows are excluded from the function output.
* Both input nodes must contain the same levels, otherwise the function will consider only the more granular function while ignoring the function with fewer levels.

**Example of the limitation:** the function is given two `EXPANDSINGLE()` inputs. However, one of the `EXPANDSINGLE()` functions possesses more levels than the other, resulting in different granularity. The function with more levels is the leading function. This leads to unexpected outputs from the `XOR()` function.

![Node formula and Data Preview showing an XOR of two EXPANDSINGLE inputs with mismatched granularity, illustrating the limitation](./images/5094231064.png)

## Example

### Typical use

This example shows that `XOR` returns 1 only when exactly one input is true. If both inputs are true or both are false, the result is 0.

**Input node:** `'A'`

| Year | Value |
| ---- | ----- |
| 2025 | 17    |
| 2026 | 0     |
| 2027 | 0     |
| 2028 | 1     |

**Input node:** `'B'`

| Year | Value |
| ---- | ----- |
| 2025 | 1     |
| 2026 | 0     |
| 2027 | 1500  |
| 2028 | 0     |

**Formula:** `XOR('A', 'B')`

| Year | XOR Result |
| ---- | ---------- |
| 2025 | 0          |
| 2026 | 0          |
| 2027 | 1          |
| 2028 | 1          |

## Related

| Function          | When to use instead                                                                          |
| ----------------- | -------------------------------------------------------------------------------------------- |
| [OR (\|\|)](/or/) | When at least one of the two inputs may be true instead of requiring exactly one to be true. |
| [AND (&&)](/and/) | When both inputs must be true at the same time instead of exactly one of them.               |
