IF Column

Create new columns with conditions

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.

The IF Column Action

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.

You write logic with the following input:

InputMeaningExampleOutput

==

Equals

[Column1] == 1

All rows where Column1 is equals to 1

!=

Does not equal

[Column] != 1

All rows where Column1 is not equal to 1

<

Less than

[NumberColumn] < 20

All rows where NumberColumn has a value less than 20

>

Larger than

[NumberColumn] > 100

All rows where NumberColumn has a value larger than 100

<=

Less than or equal to

[NumberColumn] <= 0.5

All rows where NumberColumn has a value less than or equal to 0.5

>=

Larger than or equal to

[NumberColumn] >= 150

All rows where NumberColumn has a value larger than or equal to 150

.contains()

A text column contains a certain value

[TextColumn].contains("Hello")

All rows where TextColumn contains "Hello" - for instance "Hello world"

.startswith()

A text column that begins with a certain value

[TextColumn].startswith("Hello")

All rows where TextColumn starts with "Hello" - for instance "Hello world"

.endswith()

A text column that ends with a certain value

[TextColumn].endswith("world")

All rows where TextColumn ends with "world" - for instance "Hello world"

.isna()

A number/decimal column that is null

[Column].isna()

All

.isnull()

A text column that is null

[Column].isnull()

All

&

AND -> Used to pair multiple statements together

(([NumberColumn]==1) & ([TextColumn=="Client"))

All rows where TextColumn is equal to "Client" AND NumberColumn is equal to 1. Note that both conditions must be fulfilled for the statement to be true

|

OR -> Used to determine if any conditions in a test is true

([NumberColumn]==1) & (([TextColumn=="Client") |([TextColumn]=="Customer"))

All rows where TextColumn is equal to "Client" OR "Customer" AND NumberColumn is equal to 1. Note that both conditions must be fulfilled for the statement to be true

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.

Last updated