# Logical Formulas & Operators

{% hint style="info" %}
Many of these formulas feature the boolean `True` or `False` values. To learn more about how Osmos handles `True`/`False` evaluation and casting, please see [True & False Casting](https://docs.osmos.io/data-transformations/formulas/logical-formulas/true-and-false-casting).
{% endhint %}

## And &&

#### Formula

`=and(<input 1>, [input 2], ...)`

`=<input1>&&[input2]`

**Description**

Returns `True` if every input value or argument is `True,` otherwise returns `False`.

#### Arguments

| Argument    | Required (Y/N) | Description                                                                   |
| ----------- | -------------- | ----------------------------------------------------------------------------- |
| Input 1     | Y              | The first value or condition that you want to evaluate for `True` or `False`  |
| Input 2     | N              | The second value or condition that you want to evaluate for `True` or `False` |
| ... Input N | N              | The nth value or condition that you want to evaluate for `True` or `False`    |

#### Examples

> **Example 1:**
>
> \=and(equals(5,5), equals(4,4)) = `True`
>
> \=(5=5)&&(4=4) will return `True`
>
> **Example 2:**
>
> \=and(not($"IsEmployee"), $"NorthAmericaOffice")&#x20;
>
> \=($"IsEmployee"="False")&&($"NorthAmericaOffice"="True")

## Equals =

#### Formula

`=equals(<input 1>, [input 2], ...)`

`=<input1>=[input2]...`

#### **Description**

Returns `True` if every input value or argument is equal to each other input, otherwise returns `False`

#### Arguments

| Argument | Required (Y/N) | Description                                                       |
| -------- | -------------- | ----------------------------------------------------------------- |
| Input 1  | Y              | Value evaluated along with other input values (Input 2...Input N) |

#### Examples

> **Example 1:**
>
> \=equals(5, 5, 5) will return `True`
>
> \=5=5=5 will return `True`
>
> **Example 2:**
>
> \=equals(1,1,2) will return `False`
>
> \=1=1=2 will return `False`
>
> **Example 3:**
>
> \=equals($"FirstName", "Peter")
>
> \=$"FirstName"="Peter"

## IF

#### Formula

`=if(<condition>, <value_if_true>, [value_if_false])`

`=if(<condition>, <then>, [else])`

#### **Description**

Returns value\_if\_true if the condition evaluates to `True`. Otherwise returns value\_if\_false.&#x20;

#### Arguments

<table data-header-hidden><thead><tr><th>Argument</th><th width="233.33333333333331">Required (Y/N)</th><th>Description</th></tr></thead><tbody><tr><td>Argument</td><td>Required (Y/N)</td><td>Description</td></tr><tr><td>Condition</td><td>Y</td><td>Statement, value or logical operation evaluated for TRUE or FALSE</td></tr><tr><td>value_if_true</td><td>Y</td><td>Value returned if Condition is TRUE</td></tr><tr><td>value_if_false</td><td>N</td><td>Value returned if Condition is FALSE</td></tr></tbody></table>

#### Examples

> **Example 1:**
>
> \=if(($"PurchaseDate"-currentdate())>30, "Past Due", "OK")
>
> **Example 2:**
>
> \=if(equals($"First Name", "Doe"), $"Last Name", $"First Name")\
> **Example 3:**
>
> \=if(($"Sales"<=0), $"Sales", skip())

## IFS

#### Formula

`=ifs(<condition1>, <value_if_true1>, [condition2],[value_if_true2],[condition3],[value_if_true3]...[value_if_false])`

#### **Description**

Returns value\_if\_true1 if the condition1 is `True`. Otherwise the formula continues to look for the first `True` condition. An IFS can take the place of multiple nested IF conditions. An IFS statement can be ended with a final "value\_if\_false" statement in the case that a `True` statement cannot be found. If a "value\_if\_false" is not specified and a `True` statement cannot be found, the equation will output `null.`

#### Arguments

<table data-header-hidden><thead><tr><th>Argument</th><th width="233.33333333333331">Required (Y/N)</th><th>Description</th></tr></thead><tbody><tr><td>Argument</td><td>Required (Y/N)</td><td>Description</td></tr><tr><td>Condition1</td><td>Y</td><td>Statement, value or logical operation evaluated for TRUE or FALSE</td></tr><tr><td>value_if_true1</td><td>Y</td><td>Value returned if Condition is TRUE</td></tr><tr><td>Condition2</td><td>N</td><td>Optional statement, value or logical operation evaluated for TRUE or FALSE</td></tr><tr><td>value_if_true2</td><td>N</td><td>Optional value returned if Condition is TRUE</td></tr><tr><td>value_if_false</td><td>N</td><td>Optional default value output in the case that none of the outlined conditions return true</td></tr></tbody></table>

#### Examples

> **Example 1:**
>
> \=ifs(($"Rating">=4),"Four Stars",($"Rating">=3),"Three Stars","Needs Improvement")
>
> **Example 2:**
>
> \=ifs(($"ProductCategory"=103), "Shirts & Jackets", ($"ProductCategory"=104), "Pants", "Unknown")

## Switch

#### Formula

`=switch(<$"Field">, <input1>, <value1>, [input2], [value2]...` `[default_value])`

#### **Description**

Returns a value directly corresponding to an input where that input is found in a specified field.

Arguments

<table data-header-hidden><thead><tr><th>Argument</th><th width="233.33333333333331">Required (Y/N)</th><th>Description</th></tr></thead><tbody><tr><td>Argument</td><td>Required (Y/N)</td><td>Description</td></tr><tr><td>Field</td><td>Y</td><td>The location of the data to be compared to input values</td></tr><tr><td>input1</td><td>Y</td><td>The input to be compared against the value in a specified field</td></tr><tr><td>value1</td><td>Y</td><td>The value returned when its corresponding input is equal to the value in a specified field</td></tr><tr><td>input2</td><td>N</td><td>A secondary input to be compared against the value in a specified field</td></tr><tr><td>value2</td><td>N</td><td>The value returned when its corresponding input is equal to the value in a specified field</td></tr><tr><td>default_value</td><td>N</td><td>The value returned in the case that no inputs correspond to the value of the specified field.</td></tr></tbody></table>

#### Examples

> **Example 1:**
>
> \=switch($"weekday\_number",1,"Sunday",2,"Monday",3,"Tuesday","No match")
>
> **Example 2:**
>
> \=switch($"Rank",5,"Five Star",4,"Four Star",3,"Needs Work",2,"Needs Work",1,"Needs Work","n/a")

## NotEquals !=

#### Formula

`=notequals(<input 1>, [input 2], ...)`

`=<input1>!=[input2]`

#### **Description**

Returns `False` if every input is equal to each other, otherwise returns `True`

#### Arguments

| Argument | Required (Y/N) | Description                                                       |
| -------- | -------------- | ----------------------------------------------------------------- |
| Input 1  | Y              | Value evaluated along with other input values (Input 2...Input N) |

#### Examples

> **Example 1:**
>
> \=notequals(5, 5) will return `False`
>
> \=5!=5 will return `False`
>
> **Example 2:**
>
> \=notequals(5,5,3) will return `True`
>
> \=5!=5!=3 will return `True`
>
> **Example 3:**
>
> \=equals($"FirstName", "Smith")
>
> \=$"FirstName"!="Smith"

## Or ||

#### Formula

`=or(<input 1>, [input 2], ...)`&#x20;

`=<input1>||[input2]`

#### **Description**

Returns `True` if at least one input is `True`, otherwise returns `False`

#### Arguments

| Argument    | Required (Y/N) | Description                                                               |
| ----------- | -------------- | ------------------------------------------------------------------------- |
| Input 1     | Y              | The first value or condition that you want to evaluate for TRUE or FALSE  |
| Input 2     | N              | The second value or condition that you want to evaluate for TRUE or FALSE |
| ... Input N | N              | The nth value or condition that you want to evaluate for TRUE or FALSE    |

#### Examples

> **Example 1:**
>
> \=or(equals(2,5), equals(4,4)) = `True`
>
> \=(2=5)||(4=4)
>
> **Example 2:**
>
> \=or(not($"Is Employee"), $"Lives in North America")&#x20;
>
> \=($"Is Employee"=FALSE)||($"Lives in North America"="TRUE")

## Xor ^

#### Formula

`=xor(<input 1>, [input 2], ...)`

`=<input1>^<input2>`

#### **Description**

Returns `True` if at exactly one input is true, otherwise returns `False`

#### Arguments

| Argument    | Required (Y/N) | Description                                                               |
| ----------- | -------------- | ------------------------------------------------------------------------- |
| Input 1     | Y              | The first value or condition that you want to evaluate for TRUE or FALSE  |
| Input 2     | N              | The second value or condition that you want to evaluate for TRUE or FALSE |
| ... Input N | N              | The nth value or condition that you want to evaluate for TRUE or FALSE    |

#### Examples

> **Example 1:**
>
> \=xor(equals(2,5), equals(4,4)) will return `False`
>
> \=(2=5)^(4=4) will return `True`
>
> **Example 2:**
>
> \=xor(equals(2, 5), equals(4,5)) will return `False`
>
> \=(2=5)^(4=5) will return `False`
>
> **Example 3:**
>
> \=xor(not($"Is Employee"), $"Lives in North America")
>
> \=($"Is Employee"="FALSE")^($"Lives in North America"="FALSE")

## Not

#### Formula

`=not(<input>)`

#### **Description**

Returns `True` if the given input is `False`, otherwise returns `False`.

#### Arguments

| Argument | Required (Y/N) | Description                                                   |
| -------- | -------------- | ------------------------------------------------------------- |
| Input    | Y              | Statement or operation that is evaluated for `True` condition |

#### Examples

> **Example 1:**
>
> \=not(true) = `False`
>
> **Example 2:**
>
> \=not($"Is Employee")

## Contains

#### Formula

`=contains(<input>, <content>)`

#### **Description**

Returns `True` if the given content is contained within the input argument, otherwise returns `False`.

#### Arguments

| Argument | Required (Y/N) | Description                                                               |
| -------- | -------------- | ------------------------------------------------------------------------- |
| Input    | Y              | Statement or operation that is searched for the presence of Content value |
| Content  | Y              | Value to be searched within Input argument                                |

#### Examples

> **Example 1:**
>
> \=contains("last name", "name") will return `True`
>
> **Example 2:**
>
> \=contains($"date", "2020-02-2017")
>
> **Example 3:**
>
> \=contains($"full name", $"last name")

## Iferror

#### Formula

`=iferror(<condition>, <value_if_error>,` `[value_if_no_error])`

#### **Description**

Returns value\_if\_error if the condition has an Error. Otherwise returns value\_if\_no\_error. &#x20;

#### Arguments

| Argument             | Required (Y/N) | Description                                               |
| -------------------- | -------------- | --------------------------------------------------------- |
| Condition            | Y              | Statement, value or logical operation evaluated for ERROR |
| value\_if\_error     | Y              | Value returned if Condition has an ERROR                  |
| value\_if\_no\_error | N              | Value returned if Condition does not have an ERROR        |

#### Examples

> **Example 1:**
>
> \=iferror($"request\_date", "Date Missing",$"request\_date")
>
> **Example 2:**
>
> \=iferror(divide(10,0), "Divide by zero") will return "Divide by zero"

## Less Than >

#### Formula

`=<input1> > <input2>`

#### **Description**

Returns a boolean `True` value if input1 is greater than to input2, otherwise returns `False`. Numeric values will be evaluated numerically, string values will be evaluated by lexicographical value.

#### Arguments

<table data-header-hidden><thead><tr><th>Argument</th><th width="543.3333333333333">Required (Y/N)</th><th>Description</th></tr></thead><tbody><tr><td>Argument</td><td>Required (Y/N)</td><td>Description</td></tr><tr><td>Input1</td><td>Y</td><td>Primary value for evaluation</td></tr><tr><td>Input2</td><td>Y</td><td>The second value that you want to be evaluated</td></tr></tbody></table>

#### Examples

> **Example 1:**
>
> \=5>10 will return `False`
>
> **Example 2:**
>
> \="cat">"bat" will return `True`, as "c" comes after "b" and so has a higher lexicographical value

## Less Than or Equal To >=

#### Formula

`=<input1> >= <input2>`

#### **Description**

Returns a boolean `True` value if input1 is greater than or equal to to input2, otherwise returns `False`. Numeric values will be evaluated numerically, string values will be evaluated by lexicographical value.

#### Arguments

<table data-header-hidden><thead><tr><th>Argument</th><th width="543.3333333333333">Required (Y/N)</th><th>Description</th></tr></thead><tbody><tr><td>Argument</td><td>Required (Y/N)</td><td>Description</td></tr><tr><td>Input1</td><td>Y</td><td>Primary value for evaluation</td></tr><tr><td>Input2</td><td>Y</td><td>The second value that you want to be evaluated</td></tr></tbody></table>

#### Examples

> **Example 1:**
>
> \=5>=10 will return `False`
>
> **Example 2:**
>
> \="cat">="bat" will return `True`, as "c" comes after "b" and so has a higher lexicographical value
>
> **Example 3:**
>
> \=if($"Q2Sales">=$"Q1\_Sales", "Growth","Stagnation")

## Greater Than <

#### Formula

`=<input1> < <input2>`

#### **Description**

Returns a boolean `True` value if input1 is less than than to input2, otherwise returns `False`. Numeric values will be evaluated numerically, string values will be evaluated by lexicographical value.

#### Arguments

<table data-header-hidden><thead><tr><th>Argument</th><th width="656.3333333333333">Required (Y/N)</th><th>Description</th></tr></thead><tbody><tr><td>Argument</td><td>Required (Y/N)</td><td>Description</td></tr><tr><td>Input1</td><td>Y</td><td>Primary value for evaluation</td></tr><tr><td>Input2</td><td>Y</td><td>The second value that you want to be evaluated</td></tr></tbody></table>

#### Examples

> **Example 1:**
>
> \=10>5 will return `False`
>
> **Example 2:**
>
> \="bat"<"cat" will return `True`, as "b" comes before "c" and so has a lesser lexicographical value

## Greater Than or Equal To <=

#### Formula

`=<input1> <= <input2>`

#### **Description**

Returns a boolean `True` value if input1 is less than than or equal to input2, otherwise returns `False`. Numeric values will be evaluated numerically, string values will be evaluated by lexicographical value.

#### Arguments

<table data-header-hidden><thead><tr><th>Argument</th><th width="656.3333333333333">Required (Y/N)</th><th>Description</th></tr></thead><tbody><tr><td>Argument</td><td>Required (Y/N)</td><td>Description</td></tr><tr><td>Input1</td><td>Y</td><td>Primary value for evaluation</td></tr><tr><td>Input2</td><td>Y</td><td>The second value that you want to be evaluated</td></tr></tbody></table>

#### Examples

> **Example 1:**
>
> \=10>=5 will return `False`
>
> **Example 2:**
>
> \="bat"<="cat" will return `True`, as "b" comes before "c" and so has a lesser lexicographical value
>
> **Example 3:**
>
> \=if($"Q2Sales"<=$"Q3\_Sales","Stagnation", "Growth")
