This cheat sheet provides a quick reference guide for various conditional expressions commonly used in data analysis and programming. Each expression is accompanied by its syntax, a sample usage, and a brief description.
The IF function in programming and spreadsheet formulas provides a way to perform conditional operations. It evaluates a condition and returns a value if the condition is `TRUE`, or another value if the condition is `FALSE`.
#### Syntax
```markdown
IF(expr, successCase, elseCase)
```
#### Sample
```markdown
IF({field} > 1, Value1, Value2)
Output
-`Value1` if `{field} > 1` evaluates to TRUE
-`Value2` otherwise
```
## SWITCH
The SWITCH function is a versatile tool for handling multiple cases. It evaluates the given expression (expr) against a series of patterns and returns the corresponding value of the first matching pattern. If none match, it returns the default value.
#### Syntax
```markdown
SWITCH(expr, [pattern, value, ..., default])
```
#### Sample
```markdown
SWITCH({field}, 1, 'One', 2, 'Two', '--')
Output
Switch case value based on the output of `{field}`:
-`'One'` if `{field} = 1`
-`'Two'` if `{field} = 2`
-`'--'` for the default case
```
## AND
The AND function is a logical operator that returns TRUE only if all its conditions are true.
#### Syntax
```markdown
AND(expr1, [expr2,...])
```
#### Sample
```markdown
AND({field} > 2, {field} <10)
Output
TRUE if both `{field} > 2` and `{field} < 10` evaluate to TRUE
```
## OR
The OR function is another logical operator, returning TRUE if at least one of its conditions is true.
#### Syntax
```markdown
OR(expr1, [expr2,...])
```
#### Sample
```markdown
OR({field} > 2, {field} <10)
Output
TRUE if at least one of the conditions `{field} > 2` or `{field} < 10` evaluates to TRUE