> For the complete documentation index, see [llms.txt](https://docs-v3.toucantoco.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-v3.toucantoco.com/data-management-in-datahub/datasets-in-toucan/preparing-data/overview-of-youprep-tm/add/add-conditional-column.md).

# Add conditional column

The Add conditional column allows you to create a new column based on If...Then...Else schema with possibilities to add nested conditions in order to create conditional logic for data manipulation.

The condition is expressed in the `if` parameter with a condition object, which is the same object expected by the `condition` parameter of the [filter step](/data-management-in-datahub/datasets-in-toucan/preparing-data/overview-of-youprep-tm/filter/filter-rows.md)). Conditions can be grouped and nested with logical operators `and` and `or`.

The `then` parameter only supports a string, that will be interpreted as a formula (cf. [formula step](/data-management-in-datahub/datasets-in-toucan/preparing-data/overview-of-youprep-tm/add/add-formula-column.md)). If you want it to be interpreted strictly as a string and not a formula, you must escape the string with quotes (e.g. ‘“this is a text”’).

`if...then...else` blocks can be nested as the `else` parameter supports either a string that will be interpreted as a formula (cf. [formula step](/data-management-in-datahub/datasets-in-toucan/preparing-data/overview-of-youprep-tm/add/add-formula-column.md)), or a nested if `if...then...else` object.

### Step parameters

1. `New Column` **(string)**: Enter a name for the new column that will be created based on your conditions and formulas.
2. `If Condition`: Define the condition(s) that will be evaluated.
3. `Then Formula`: Specify the formula to be applied when the condition is true.
4. `Else Formula`: Specify the formula to be applied when the condition is false.

### Example

**Input**

<figure><img src="/files/COJaluNgt0am0VIVxT5w" alt=""><figcaption><p>Add - Add conditional column input</p></figcaption></figure>

**Configuration**

```json
{
    "new_column": "Category",
    "if": {
            "and": [
                {
                        "column": "Price",
                        "operator": "ge",
                        "value": 50
                },
                {
                        "column": "Stock",
                        "operator": "gt",
                        "value": 10
                },
            ]
        },
    "then" "Premium",
    "else": "Standard"    
}
```

Where `gt`: greater than and `ge`: greater than or equal to

**Output**

<figure><img src="/files/eSrg8WqamKVd4Hx53xRP" alt=""><figcaption><p>Add - Add a conditional column output</p></figcaption></figure>

{% hint style="info" %}
**Defining Conditions**

You can create three types of conditions:

1. **Simple Condition**:
   * Column Name: Enter the name of the column you want to filter on.
   * Operator: Choose from operators like equals, not equals, greater than, less than, etc.
   * Value: Enter the value to compare against.
2. **AND Condition**: Combine multiple conditions that must all be true.
3. **OR Condition**: Combine multiple conditions where at least one must be true.
   {% endhint %}

{% hint style="info" %}
**Operators**

The following operators are available for conditions:

* eq (equals)
* ne (doesn't equal to)
* gt (is greater than)
* ge (is greater than or equal to)
* lt (is less than)
* le (is less than or equal to)
* in (is one of)
* nin (is not one of)
* matches (matches pattern)
* notmatches (doesn't match pattern)
* isnull (is null)
* notnull (is not null)
* from (starting in/on)
* until (ending in/on)
  {% endhint %}

{% hint style="info" %}

#### Formulas

For the "Then" and "Else" parts, you can enter formulas that will be applied based on the condition results. These can be simple values or complex expressions. See the [formula step](/data-management-in-datahub/datasets-in-toucan/preparing-data/overview-of-youprep-tm/add/add-formula-column.md) for more information.
{% endhint %}

{% hint style="info" %}

#### Nested Conditions

You can create nested conditions by using another If...Then...Else structure in the "Else" part of your condition.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs-v3.toucantoco.com/data-management-in-datahub/datasets-in-toucan/preparing-data/overview-of-youprep-tm/add/add-conditional-column.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
