> ## Documentation Index
> Fetch the complete documentation index at: https://oculon.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Conditional logic

> Use conditional logic to make formulas respond to time, context, and business rules in Oculon.

Conditional logic lets a variable return different values when conditions change. Use it for cutoffs, seasonality, status flags, and exception cases inside a model.

## Start with the core pattern

In Oculon, conditional logic follows this pattern:

```text theme={null}
if condition then value_if_true else value_if_false
```

Every branch should be intentional. If the business rule has two outcomes, make both outcomes explicit.

## Common uses

Conditional logic is especially useful when you need to:

* Switch behavior around the [Last actual date](https://oculon.mintlify.site/concepts/data-and-structure/time/last-actual-date.md)
* Apply different logic to different months or quarters
* Return flags such as `1` and `0` for active or inactive states
* Protect a formula from blank or missing values
* Handle exceptions without rewriting the full formula

## Combine conditions with and and or

Use `and` when multiple conditions must all be true. Use `or` when any one of the listed conditions should trigger the branch.

```text theme={null}
if timestep > lastActualDate and Volume > 0 then Price * Volume else Revenue
if Region = North or Region = West then Regional target else Standard target
```

Keep combined conditions readable. If a branch needs too many checks, move the checks into helper variables first.

## Use in and not in for list-based rules

Use `in` and `not in` when one formula should react to a defined list of values.

```text theme={null}
if month in [11, 12, 1, 2] then Winter demand else Base demand
if quarter not in [1, 4] then Midyear plan else Seasonal plan
```

This pattern works well for seasonality, fiscal gates, and grouped exception logic.

## Handle nested conditions carefully

Nested conditions are valid, but they become difficult to review quickly.

```text theme={null}
if timestep <= lastActualDate then Actual revenue
else if month in [11, 12] then Holiday forecast
else Baseline forecast
```

Keep each branch tied to one clear business rule.

## Use conditional logic around the Last actual date

One of the most common formula patterns is a cutoff-based switch.

```text theme={null}
if timestep <= lastActualDate then Actual bookings else Planned bookings
```

Prefer tying the cutoff to the [Last actual date](https://oculon.mintlify.site/concepts/data-and-structure/time/last-actual-date.md) instead of a hard-coded month. Many models also use separate **actual formula** and **planned formula** fields; see [Variable behavior](https://oculon.mintlify.site/concepts/data-and-structure/variables/variable-behavior.md).

## When to move branches into helper variables

Use a helper variable when:

* The same condition appears in more than one formula
* The formula mixes business logic and exception handling
* A reviewer would need to read the line twice to understand it
* The condition is important enough to deserve a clear name

## Common mistakes

Watch for these issues:

* Hiding cutoff logic inside a long nested expression
* Mixing hard-coded dates with [relative time](https://oculon.mintlify.site/concepts/data-and-structure/time/relative-time.md) logic
* Using many branches when one helper variable would be clearer
* Returning blanks or text values when the downstream formula expects a number

## Related pages

* [Formula basics](https://oculon.mintlify.site/concepts/modeling/formulas/overview.md)
* [Functions](https://oculon.mintlify.site/concepts/modeling/formulas/functions.md)
* [Helper variables and modifiers](https://oculon.mintlify.site/concepts/modeling/formulas/helper-variables-and-modifiers.md)
* [Last actual date](https://oculon.mintlify.site/concepts/data-and-structure/time/last-actual-date.md)
* [Common formula patterns](https://oculon.mintlify.site/concepts/modeling/formulas/common-formula-patterns.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.