--- title: 'Conditional Expressions' description: 'This article explains various conditional expressions that can be used in formula fields.' tags: ['Fields', 'Field types', 'Formula'] keywords: ['Fields', 'Field types', 'Formula', 'Create formula field', 'Conditional expressions'] --- 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. ## IF 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 ``` :::tip Logical operators, along with Numerical operators can be used to build conditional `expressions`. Examples: ``` IF({marksSecured} > 80, "GradeA", "GradeB") ``` ``` SWITCH({quarterNumber}, 1, 'Jan-Mar', 2, 'Apr-Jun', 3, 'Jul-Sep', 4, 'Oct-Dec', 'INVALID' ) ``` ::: ## Related Articles - [Numeric and Logical Operators](015.operators.md) - [Numeric Functions](020.numeric-functions.md) - [String Functions](030.string-functions.md) - [Date Functions](040.date-functions.md)