> For the complete documentation index, see [llms.txt](https://resources.less.tech/less-tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://resources.less.tech/less-tech/modelling/action-guides/new-columns/if-column.md).

# IF Column

<figure><img src="/files/x8gRXt9gJC8d3FpC7VaW" alt=""><figcaption></figcaption></figure>

IF Columns mean you can create new columns with a condition. The structure follows a pretty basic:

```
IF [column-a] IS 
[equal to/not equal to/larger than/smaller than] 
[your-number or your-text or column-b] 
THEN
[your-number or your-text or column-C]
ELSE 
[your-number or your-text or column-d]
```

In sum, the IF Column uses a conditional statement where it evaluates each statement and **if** a statement is true **then** the then-statement is added to the new column. Translated to human language it could be something like *if my revenue column is larger than 400 then my new client\_type column should be "enterprise client" otherwise it should be "normal client".* You can watch an example of how to use the IF Column Action below.

{% embed url="<https://loom.com/share/41950520f1d641fe96e831a3d94914df>" %}
The IF Column Action
{% endembed %}

## Writing Logic

In Less, you have to enter your logic in the fields below. You can use **\[** to bring up columns from your dataset. This is the basic logic:

1. In the IF field you add the condition: if this is true for a row
2. In the THEN field, you add what should happen if the above is true: take this value if the above is true
3. You can create new condition with the ELSEIF button
4. When you done add you ELSE field. THis is the catch all: if the IF-condition is not true, then you want this value.

<figure><img src="/files/pdypKkatboSMm2RH0NOS" alt=""><figcaption></figcaption></figure>

You write logic with the following input:

<table><thead><tr><th width="140">Input</th><th width="145">Meaning</th><th width="279">Example</th><th>Output</th></tr></thead><tbody><tr><td>==</td><td>Equals</td><td>[Column1] == 1</td><td>All rows where Column1 is <strong>equals</strong> to 1</td></tr><tr><td>!=</td><td>Does not equal</td><td>[Column] != 1</td><td>All rows where Column1 is <strong>not equal</strong> to 1</td></tr><tr><td>&#x3C;</td><td>Less than</td><td>[NumberColumn] &#x3C; 20</td><td>All rows where NumberColumn has a value <strong>less than</strong> 20</td></tr><tr><td>></td><td>Larger than</td><td>[NumberColumn] > 100</td><td>All rows where NumberColumn has a value <strong>larger than</strong> 100</td></tr><tr><td>&#x3C;=</td><td>Less than or equal to</td><td>[NumberColumn] &#x3C;= 0.5</td><td>All rows where NumberColumn has a value <strong>less than or equal</strong> to 0.5</td></tr><tr><td>>=</td><td>Larger than or equal to</td><td>[NumberColumn] >= 150</td><td>All rows where NumberColumn has a value <strong>larger than or equal</strong> to 150</td></tr><tr><td>.contains()</td><td>A text column contains a certain value</td><td>[TextColumn].contains("Hello")</td><td>All rows where TextColumn <strong>contains</strong> "Hello" - for instance "Hello world"</td></tr><tr><td>.startswith()</td><td>A text column that begins with a certain value</td><td>[TextColumn].startswith("Hello")</td><td>All rows where TextColumn <strong>starts with</strong> "Hello" - for instance "Hello world"</td></tr><tr><td>.endswith()</td><td>A text column that ends with a certain value</td><td>[TextColumn].endswith("world")</td><td>All rows where TextColumn <strong>ends with</strong> "world" - for instance "Hello world"</td></tr><tr><td>.isna()</td><td>A number/decimal column that is null</td><td>[Column].isna()</td><td>All </td></tr><tr><td>.isnull()</td><td>A text column that is null</td><td>[Column].isnull()</td><td>All</td></tr><tr><td>&#x26;</td><td>AND -> Used to pair multiple statements together</td><td>(([NumberColumn]==1) <strong>&#x26;</strong> ([TextColumn=="Client"))</td><td>All rows where TextColumn is equal to "Client" <strong>AND</strong> NumberColumn is equal to 1. Note that both conditions must be fulfilled for the statement to be true</td></tr><tr><td>|</td><td>OR -> Used to determine if any conditions in a test is true</td><td>([NumberColumn]==1) <strong>&#x26;</strong> (([TextColumn=="Client") <strong>|</strong>([TextColumn]=="Customer"))</td><td>All rows where TextColumn is equal to "Client" <strong>OR</strong> "Customer" <strong>AND</strong> NumberColumn is equal to 1. Note that both conditions must be fulfilled for the statement to be true</td></tr></tbody></table>

{% hint style="warning" %}
You **must** use parentheses around the condition when you use either **AND** or **OR** clauses. To illustrate:

This does not work: *\[TextColumn=="Client" &* *\[TextColumn]=="Customer"*

But this does work: ***((**\[TextColumn=="Client"**)** | **(**\[TextColumn]=="Customer"**))***\
\
You can pass as many AND and OR clauses into a statement as you want as long as you remember parentheses.
{% 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://resources.less.tech/less-tech/modelling/action-guides/new-columns/if-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.
