# Logical functions
URL: https://docs.valsight.ai/logical-functions/
Description: Use this category when you need conditions, comparisons, and branching logic in formulas.
Use this category when you need **conditions, comparisons, and branching logic** in formulas.

These functions help you build boolean-style expressions, typically represented as `1` or `0`, and use them to select values, create flags, or diagnose unexpected results.

## Start here if…

* You are **looking up a logical function by name**, for example `IF`, `EQ`, `GT`, `AND`, `TRUE`, `FALSE`, or `IS_NA`
* You want to **compare** similar logical functions and understand when to use which one
* You need function-specific notes, limits, or troubleshooting

## Not here if…

* You want comparison operators and boolean keywords as operators, for example `>`, `=`, `AND`, `OR`, `NOT` → see [Comparisons & boolean operators](/comparisons-boolean-operators/)
* You want numeric transformations such as `ROUND`, `ABS` or `MIN`/`MAX`→ see [Math & numeric](/math-numeric/)

## Mental model

* Logical functions usually return `1` or `0` across the same dimensionality as their inputs
* Conditions are most commonly used inside `IF` to select between two results
* Missing values can affect conditions; use `IS_NA` when results look unexpectedly empty or incomplete

## Common patterns

| Name                           | What it does                                                            | Formula                              |
| ------------------------------ | ----------------------------------------------------------------------- | ------------------------------------ |
| Apply a business rule          | Use when you want to cap, floor, or branch values based on a condition. | `IF('Margin' < 0, 0, 'Margin')`      |
| Create a threshold flag        | Use when you want to mark where values exceed a threshold.              | `GT('Revenue', 100000)`              |
| Compare two nodes for equality | Use when you want to create match or mismatch flags for validation.     | `EQ('Actuals', 'Plan')`              |
| Combine multiple conditions    | Use when you want to build between-rules or multi-part checks.          | `AND(GT('Node', 0), LT('Node', 10))` |
| Invert a condition             | Use when you want the opposite of an existing rule.                     | `NOT(EQ('Status', 1))`               |
| Check for undefined values     | Use when you want to flag undefined values before comparisons.          | `IS_NA('Node')`                      |

## Functions in this category

**Branching**

| Function   | Description                                                                           |
| ---------- | ------------------------------------------------------------------------------------- |
| [IF](/if/) | Returns value\_if\_true when a condition is true; otherwise returns value\_if\_false. |

**Function equivalents of operators**

| Function          | Description                                                                              |
| ----------------- | ---------------------------------------------------------------------------------------- |
| [EQ (=)](/eq/)    | Returns 1 (true) if matching row values across two nodes are equal; otherwise 0 (false). |
| [NEQ (!=)](/neq/) | Returns 1 (true) where matching values of two nodes are not equal.                       |
| [GT (>)](/gt/)    | Returns 1 (true) where the first input is greater than the second.                       |
| [GTE (>=)](/gte/) | Returns 1 (true) where the first input is greater than or equal to the second.           |
| [LT (<)](/lt/)    | Returns 1 (true) where the first node’s values are less than the second.                 |
| [LTE (<=)](/lte/) | Returns 1 (true) where the first node’s values are less than or equal to the second.     |
| [AND (&&)](/and/) | Returns 1 (true) if both inputs are true; otherwise 0 (false).                           |
| [OR (\|\|)](/or/) | Returns 1 (true) if at least one of the two inputs is true; otherwise 0 (false).         |
| [NOT](/not/)      | Inverts logical values (non-zero becomes 0; zero becomes 1).                             |
| [XOR](/xor/)      | Returns 1 (true) if exactly one of two inputs is true (exclusive OR).                    |

**Defined / undefined helpers**

| Function          | Description                                                                                  |
| ----------------- | -------------------------------------------------------------------------------------------- |
| [TRUE](/true/)    | Returns 1 (true) for every defined value in the node.                                        |
| [FALSE](/false/)  | Returns 0 (false) for every defined value in the node.                                       |
| [IS\_NA](/is-na/) | Returns 1 (true) where values are undefined in the input node’s dimensionality; otherwise 0. |

## Choosing between similar functions

**IF vs flags (EQ/GT/LT/…)**

* Use `EQ`, `GT`, `LT`, and similar functions when you need a `1`/`0` flag for validation, filtering, or diagnostics
* Use `IF` when you want to return one of two result values

**EQ vs NEQ**

* Use `EQ` to mark matches
* Use `NEQ` to mark mismatches

**GT/GTE vs LT/LTE**

* Use `GT` or `GTE` for above-threshold rules
* Use `LT` or `LTE` for below-threshold rules

**AND/OR vs XOR**

* Use `AND` when all conditions must hold
* Use `OR` when any condition may hold
* Use `XOR` when exactly one condition should hold

**IS\_NA vs FALSE/TRUE**

* Use `IS_NA` to detect undefined values
* Use `TRUE` or `FALSE` when you want a defined `1` or `0` result across the defined intersections of a node

## Pitfalls & troubleshooting

* **IF result looks incomplete:** check whether the condition is undefined for some intersections; use `IS_NA` to spot where inputs are missing
* **Cube size risk:** `IS_NA` expands to a fully expanded cube and can hit maximum cube size
* **Conditions look wrong:** check both operands at the same intersection in Data preview; the root cause is often upstream values, not the comparison itself
* **Multi-part logic is hard to debug:** split logic into helper nodes, then combine with `AND` or `OR`
* **Between logic:** make it explicit with `AND(GTE(...), LTE(...))` rather than relying on a single comparison
* **Missing vs zero confusion:** review [Troubleshooting guide](/troubleshooting-guide/) when results look unexpectedly false or empty

## Related documentation

* [Comparisons & boolean operators](/comparisons-boolean-operators/): operator syntax for conditions
* [Math & numeric](/math-numeric/): use `MIN`/`MAX` for simple caps and floors
* [Troubleshooting guide](/troubleshooting-guide/): missing values and unexpected results
* [Function catalog](/function-catalog/): full signatures, parameters, and examples
