# IF Column

<figure><img src="https://1596277999-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaSJL6Od4KuV8hrdCZbXp%2Fuploads%2F7c3y8kozAaNO5y70eYYo%2Fanimation_500_la9zfax0.gif?alt=media&#x26;token=f069558b-f2e3-40f6-a479-26be6f458183" 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="https://1596277999-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaSJL6Od4KuV8hrdCZbXp%2Fuploads%2FwGsnMfYnxhER2lJZzxhb%2FCleanShot%202023-04-06%20at%2010.53.47.png?alt=media&#x26;token=ca2341e7-e32b-420e-b59d-655eb53045df" 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 %}
