> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://help.sigmacomputing.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://help.sigmacomputing.com/_mcp/server.

# If

The **If** function returns a value based on a conditional statement. The function evaluates conditions in order, and returns the specified **value** for the first condition that is true. Conditions after the first true condition are never evaluated. If no conditions are true, the **else** value is returned.

## Syntax

```
If(condition 1, value 1, [condition 2], [value 2],..., [else])
```

Function arguments: 

* **condition 1** (required) Logical condition that returns a result that is either True or False.
* **value 1** (required) The value to be returned if its preceding condition is True.
* **condition 2+, value 2+** (optional) Several If/Then pairs can be listed in a single function. Every supplied condition must have a corresponding value.
* **else** (optional) The value to be returned if no conditionals evaluate to True. 

If an **Else** argument is not specified, a Null result is returned by default when no conditions are met.

You can use [operators](/docs/operators-overview) in conditions.

## Notes

The function evaluates conditions in order, and returns the **value** for the first true condition. Because of this, the order of conditions can change the output of the function.

## Examples

```
If([size] < 3, "small", [size] < 6, "medium", "large")
```

Groups records into categories based on size. Returns `small` if `[size]` less than 3, `medium` if `[size]` is less than 6, and `large` if `[size]` is greater than or equal to 6.

```
If([revenue] - [cost] > 0, "profit", "loss")
```

Categorizes a record as a profit or a loss based on revenue and cost. If `[revenue] - [cost]` is greater than 0, returns `profit`. Otherwise, returns `loss`.

```
If([Product Family] = "Cameras & Camcorders" OR [Product Family] = "Camera Accessories", "Photography")
```

Categorizes records in the product family with an overarching product type using the "OR" [operator](/docs/operators-overview). If `[Product Family]` is either `Cameras & Camcorders` or `Camera Accessories`, returns `Photography`.

```
If(IsNull([Text]), 1, 0)
```

Checks if the column `[Text]` is `Null`. Returns `1` if it is null, and `0` if it is not.

```
If([Number] > 0, If(Mod([Number], 2) = 0, "Even", "Odd"), "Negative")
```

Checks if a number is positive from the column `[Number]`. If it is positive, it checks if the number is even or odd. Otherwise, it returns `Negative`. This is a nested **If** statement, meaning the **If** statement in the second argument will only ever be evaluated for the outcome `"Even"` or `"Odd"` if the first condition of the outer **If** statement - `[Number] > 0` - is true.

* For a row where `[Number]` has a value 7, this returns `Odd`.
* For a row where `[Number]` has a value 2, this returns `Even`.
* For a row where `[Number]` has a value -1, this returns `Negative`.

## Related resources

* [SumIf](/docs/sumif)
* [CountIf](/docs/countif)
* [Switch](/docs/switch)