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

# IF Column

> Create new columns with conditions

The IF Column tool is a very powerful way to create new custom columns. The best way to explain how it works is with an example. Think of it like choosing what to wear based on the weather. If it's raining, you wear a raincoat. If it's sunny, you wear a t-shirt. If it's cold, you wear a sweater.
With the IF Column tool you tell Less to make similar choices based on your data: "*If this is true, do this thing. If that's true, do that thing instead.*" Just like you check the weather before deciding what to wear, Less checks certain conditions before deciding what to do next.

<Tip>
  The IF Column tool is also known as conditional statements, and is similar to a CASE statement in SQL and an =IF() function in Excel
</Tip>

<Note>
  Note that our Syntax also supports date math calculations. See more in the [Syntax](/canvas/syntax) section.
</Note>

<Frame caption="Our example visualised. Note that each row in your columns will go through this decision tree.">
  <img className="rounded-md" src="https://mintcdn.com/less-51/c7zKg7c6pRrkgPQD/images/tools/if-column/Illustration.png?fit=max&auto=format&n=c7zKg7c6pRrkgPQD&q=85&s=f257da362d97e894a6a3158b20ecdc77" width="1595" height="1035" data-path="images/tools/if-column/Illustration.png" />
</Frame>

<br />

<Frame caption="Our example in Less">
  <img className="rounded-md" src="https://mintcdn.com/less-51/ZjPXJAIsRGCMglYF/images/tools/if-column/Example.png?fit=max&auto=format&n=ZjPXJAIsRGCMglYF&q=85&s=2d42b816ee676ac785401a00f93ce03e" width="2194" height="1556" data-path="images/tools/if-column/Example.png" />
</Frame>

<br />

<Frame caption="Our full configuration in Less">
  <img className="rounded-md" src="https://mintcdn.com/less-51/ZjPXJAIsRGCMglYF/images/tools/if-column/ExampleConfig.png?fit=max&auto=format&n=ZjPXJAIsRGCMglYF&q=85&s=e8194afd0f8d335c55dd13be87f7f110" width="1568" height="2859" data-path="images/tools/if-column/ExampleConfig.png" />
</Frame>

### Configuration

<Note>
  Your conditions are evaluated in the order you create them. In other words, if a cell value is equal to `Hello World` and your first condition is  `IF [column].LEFT(5)="Hello" THEN "Something"` and your second condition is `IF [column].RIGHT(5)="World" THEN "SomethingElse"` then your output will rely on the **first true condition** which will lead to an output of `Something`
</Note>

<Steps>
  <Step title="Column name">
    The IF Column tool will create a new column. Use this input to name it.
    <Tip>This input supports column references to overwrite a specific column as well as parameters.</Tip>
  </Step>

  <Step title="Add Your Condition(s)">
    Add your conditions and then clauses. The first condition and clause is required but additional ELSEIF pairs are optional. You can add them with the "+ Add condition (elseif)" button.

    <Warning>
      It is **very important** that your 'When' condition always defaults to a boolean value. Now what does that mean? That means that the statement '"hello"' is not a boolean value. However, \[column]="hello" is a boolean value because it is either true or false for a given row. <br /><br />You'll get an error if you try to use a non-boolean value in your 'When' condition.
    </Warning>

    <Tip>You can use syntax, column references and parameters in your conditions and clauses. This is what makes the IF Column tool so powerful. See more in the [Syntax](/canvas/syntax) section.</Tip>
  </Step>

  <Step title="Add Else Clause">
    Add a fallback syntax (else clause). All the rows that doesn't fulfill any of your conditions from Step #2 will get this value.
  </Step>
</Steps>

You can move conditions up and down in the list by clicking the up and down arrows to the right hand side of the configuration window. You can also delete individal conditions by clicking the "X" icon.

### Example: Working with boolean columns

In this example, we want to create a new column based on the value of a boolean column. See how we use ISFALSE syntax to catch false values - we could use ISTRUE syntax to catch true values.

<Frame>
  <img className="rounded-md" src="https://mintcdn.com/less-51/ZjPXJAIsRGCMglYF/images/tools/if-column/Boolean.png?fit=max&auto=format&n=ZjPXJAIsRGCMglYF&q=85&s=cebc01d83979da0a8d11f1bb26321409" width="1882" height="1184" data-path="images/tools/if-column/Boolean.png" />
</Frame>

### Example: Creating nulls

In this example, we want to create nulls if the value in our *int\_col* is lower than 500. Notice how we use the constant NULL (see [Syntax](/canvas/syntax)) in our 'Then' clause to create nulls.

<Frame>
  <img className="rounded-md" src="https://mintcdn.com/less-51/ZjPXJAIsRGCMglYF/images/tools/if-column/Nulls.png?fit=max&auto=format&n=ZjPXJAIsRGCMglYF&q=85&s=6dce187c8db6f382166e5919af1b0a8a" width="3936" height="2660" data-path="images/tools/if-column/Nulls.png" />
</Frame>

### Example: More syntaxing

Now we're diving a bit deeper into syntaxing. Here we saying: "If the first character from the right of my *text\_col* is an '1' OR '2' OR '3' I want to create a new column with the value 'Catch this row, please'. If neither of those is true then I want to take the characters from 0 to 10 of my *format\_col* and make it uppercase.

<Frame>
  <img className="rounded-md" src="https://mintcdn.com/less-51/ZjPXJAIsRGCMglYF/images/tools/if-column/MediumDifficult.png?fit=max&auto=format&n=ZjPXJAIsRGCMglYF&q=85&s=c0ef0b2530410d211f090aaf96480f31" width="2194" height="1556" data-path="images/tools/if-column/MediumDifficult.png" />
</Frame>

### Example: Even more syntaxing!

Okay, now things are getting fun. We're adding two conditions below and using parameters in one of them. In the second condition we're also working with dates comparisons.

<Frame>
  <img className="rounded-md" src="https://mintcdn.com/less-51/ZjPXJAIsRGCMglYF/images/tools/if-column/Hard.png?fit=max&auto=format&n=ZjPXJAIsRGCMglYF&q=85&s=25c1286466a1062eef83ad24cafe2ba2" width="2194" height="1556" data-path="images/tools/if-column/Hard.png" />
</Frame>

<br />

<Frame>
  <img className="rounded-md" src="https://mintcdn.com/less-51/ZjPXJAIsRGCMglYF/images/tools/if-column/HardConfig.png?fit=max&auto=format&n=ZjPXJAIsRGCMglYF&q=85&s=81f589a929cafa89dcbea39bcfebdcdc" width="1552" height="2246" data-path="images/tools/if-column/HardConfig.png" />
</Frame>
