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

# Reuse expression logic

> Define expression logic once and reference it across multiple Calculated Channels, Rules, and User-Defined Functions.

Write a CEL expression once as a User-Defined Function and call it by name wherever you need it, keeping logic consistent and reducing duplication across your workspace.

## Before you begin

* You are familiar with how Sift organizes data into Assets, Channels, and Runs.
  * If not, see [Understand Assets, Channels, and Runs](/documentation/get-started/data-model).
* You know the CEL expression logic you want to reuse. If you need help writing expressions, see [Expression syntax](/documentation/reference/expression-syntax).

## How reusable expression logic works

A **User-Defined Function** is a reusable CEL expression that can be called by name inside the expressions of Calculated Channels, Rules, and other User-Defined Functions. It does not produce a signal on its own.

It acts as a building block that encapsulates a piece of logic, such as a threshold calculation or a normalization formula, that you want to apply consistently across multiple places in your workspace.
Each input in a User-Defined Function is assigned a shorthand variable (`$1`, `$2`, and so on) based on the order you define them. You use these variables to write the expression, just as you would in a Calculated Channel.

### Example

For example, say you want to convert temperature readings from Celsius to Fahrenheit across multiple assets.

Instead of writing `($1 * 9/5) + 32` in every Calculated Channel and Rule separately, you define it once as a User-Defined Function called `celsius_to_fahrenheit` with the expression `($1 * 9/5) + 32`.
You can then reference it in Calculated Channels, Rules, and other User-Defined Functions:

* In a Calculated Channel: `celsius_to_fahrenheit($1)`
* In a Rule: `celsius_to_fahrenheit($1) > 200`

If the conversion logic changes, you update the function once and the change applies everywhere it is referenced automatically.

## Create a User-Defined Function

1. In **Sift's** homepage, click the <Icon icon="function" /> **User-Defined Functions** tab.
2. Click **New Function**.
3. In the **User-defined function name** box, enter a name for the function. For naming requirements, see [User-Defined Functions settings](/documentation/reference/user-defined-functions-settings#settings).
4. Optional: In the **Description** box, enter a description of what the function does.
5. In the **Input Channels** box, select a data type for the first input (`$1`).
   * To add more inputs, click <Icon icon="plus" /> **Add input Channel** and select a data type for each additional input.
6. In the **Expression** box, write the CEL expression using the defined input variables. For supported syntax, see [Expression syntax](/documentation/reference/expression-syntax).
7. Optional: In the **Preview** section, click <Icon icon="plus" /> **Select Run** to select a Run, then review the plot to confirm the function produces the expected values against the input Channels.
8. Click **Save**.

## Verify the function

You can confirm the User-Defined Function is working correctly in two ways:

* **During creation**: In the **Preview** section, select a Run, and review the output to confirm the expression produces the expected values before saving.
* **After saving**: The function appears in the **User-Defined Functions** section of the Expression Syntax panel. Call it in a Rule, Calculated Channel, or other User-Defined Function to confirm it behaves as expected.

## Reference

* [User-Defined Functions settings](/documentation/reference/user-defined-functions-settings)
* [Expression syntax](/documentation/reference/expression-syntax)
