SWITCH Function
Purpose
Evaluates one value (called the expression) against a list of values, and returns the result corresponding to the first matching value. If there is no match, an optional default value may be returned.
Syntax
EXCEL
=SWITCH(expression, val1, result1, [val2, result2], ..., [default])
Arguments Breakdown
| Argument | Required? | Description |
|---|---|---|
expression |
Required | The value or reference to be compared against val1, val2, etc. |
val1 |
Required | A value that is compared against expression. |
result1 |
Required | The corresponding result to be returned when val1 matches expression. |
default |
Optional | A value to return if no matches are found. If omitted and no match is found, #N/A is returned. |
Practical Examples
1. Currency Code Expansion
From Formulas_&_Functions_Part_2.xlsx (Sheet Logical ):
EXCEL
=SWITCH(A2,
"USD", "US Dollar",
"EUR", "Euro",
"EGP", "Egyptian Pound",
"SAR", "Saudi Riyal",
"Other Currency"
)
2. Department ID Mapping
EXCEL
=SWITCH(DeptID, 1, "Sales", 2, "Marketing", 3, "Finance", "General")
SWITCH vs IFS
IFStests multiple different boolean expressions:=IFS(A1>100, "High", B1="Yes", "Approved").SWITCHevaluates a single expression against exact values:=SWITCH(Status, "O", "Open", "C", "Closed"). It avoids repeating the variable name in every condition.
Related Knowledge
- Notes: 03 Conditional Logic and Decision Making
- Workbook:
11_Demos_and_Workbooks/03_Formulas_and_Functions/Formulas_&_Functions_Part_2.xlsx(Sheet:Logical)