---
title: The “NOT” Operator
description: "In Assette, expressions are powerful tools used within Data Objects and Data Blocks to manipulate, compare, and evaluate data for client reports and presentations. The **`not`** operator is a fundamental logical operator that inverts the truth value of a condition.…"
url: "https://learn.assette.com/docs/the-not-operator/"
updated: "2024-11-19"
category: Developers / Developer Tools / Data Object Editor / Expressions
---

# The “NOT” Operator

In Assette, expressions are powerful tools used within Data Objects and Data Blocks to manipulate, compare, and evaluate data for client reports and presentations. The **`not`** operator is a fundamental logical operator that inverts the truth value of a condition. It allows you to negate a Boolean expression, enabling more complex conditional logic and data filtering within your expressions.

This article provides a comprehensive overview of how the `not` operator works in Assette expressions, including its purpose, syntax, usage examples, and practical applications.

## Purpose of the `not` Operator

The `not` operator is used to invert the Boolean value of a condition or expression:

- **`True`** becomes **`False`**.
- **`False`** becomes **`True`**.

By negating conditions, the `not` operator allows you to express logic in a more flexible and sometimes more intuitive way, especially when dealing with exclusions or the opposite of a specific condition.

## Syntax of the `not` Operator

**`condition`**: A logical condition or expression that returns `True` or `False`.

**Note**: It is good practice to use parentheses to group the condition being negated for clarity, especially in complex expressions, though technically not required.

```
not (condition)
```

## Understanding How It Works

When you use the `not` operator in an expression, Assette evaluates the condition and then inverts its Boolean value:

- If `condition` evaluates to `True`, `not condition` returns `False`.
- If `condition` evaluates to `False`, `not condition` returns `True`.

## Examples of Using the `not` Operator

### Simple Negation

**Evaluation:**

- If `price > 100` is `True`, meaning `price` is greater than 100, then `not (price > 100)` is `False`.
- If `price > 100` is `False`, meaning `price` is less than or equal to 100, then `not (price > 100)` is `True`.

```
not (price > 100)
```

### Negating Equality

****Evaluation**:**

- Returns `False` if `status` is `"Active"`.
- Returns `True` if `status` is not `"Active"`.

```
not (status == "Active")
```

### Negating a Compound Condition

**Evaluation:**

- Returns `True` if either `age` is less than 18 **or** `citizenship` is not `"Citizen"`.
- Returns `False` only if `age` is 18 or older **and** `citizenship` is `"Citizen"`.

```
not (age >= 18 and citizenship == "Citizen")
```

## Practical Use Cases

1. **Data Filtering:**Exclude records that meet a certain condition.
2. **Conditional Calculations:** Apply calculations when a condition is not met.

## Important Considerations

### Operator Precedence

- **Order of Evaluation:** In Assette expressions, the `not` operator has higher precedence than `and` and `or`. However, it's recommended to use parentheses to make the expression's intent clear.

### Writing for Clarity

- **Grouping Conditions:** Always use parentheses around the condition being negated.
- **Logical Equivalents:** Sometimes, negating a compound condition using `not` can be rephrased for clarity (i.e., De Morgan's Laws)

### Null and Undefined Values

- **Null Checks:** Use `HasValue()` before applying `not` if there is a possibility of null or undefined variables to prevent errors.

## Best Practices

1. **Use Parentheses for Clarity:** Always enclose the condition being negated within parentheses to ensure correct evaluation and improve readability.
2. **Simplify Expressions:** Consider simplifying expressions using logical equivalents or De Morgan's Laws when appropriate.
3. **Descriptive Variable Names:** Use meaningful variable names to make expressions self-explanatory.
4. **Test Expressions:** Regularly test expressions with different data inputs to ensure they work as intended.
5. **Handle Null Values:** Use `HasValue()` to check for nulls before evaluating conditions that may involve null variables.
