SWITCH


Returns a different value depending on whether a match was found or not

Syntax:

SWITCH(value, value_to_match, value_to_return_if_match, value_to_return_if_no_match)


SWITCH tests value against value_to_match.

It returns value_to_return_if_match if value was found in value_to_match otherwise returns value_to_return_if_no_match.


Example:

If A1 contains 1:

SWITCH(A1, 1, "Matches", "Does not match")

returns Matches


If A1 contains 2:

SWITCH(A1, 1, "Matches", "Does not match")

returns Does not match



A

B

1
1
Matches

Application:

Customer Feedback Categorization


Imagine you run an online store, and you collect customer feedback where customers rate their experience on a scale of 1 to 5. You want to categorize these numerical ratings into descriptive labels for easier analysis (e.g., "Very Poor," "Poor," "Average," "Good," "Excellent").


Table:

Customer ID

Rating

Feedback Category

A
B
C
1
101
4
Good
2
102
2
Poor
3
103
5
Excellent
4
104
1
Very Poor
5
105
3
Average
6
106
5
Excellent
7
107
4
Good

The SWITCH Formula:

To get the "Feedback Category" in column C, you would enter the following formula into cell C1:

SWITCH(B1,
1, "Very Poor",
2, "Poor",
3, "Average",
4, "Good",
5, "Excellent",
"Invalid Rating"
)


Explanation of the Formula:

  • B1: This is the expression or the value that the SWITCH function will evaluate. In this case, it's the customer's rating.
  • 1, "Very Poor": This is the first pair of value1, result1. If the value in B1 is 1, the function will return "Very Poor".
  • 2, "Poor": If B1 is 2, it returns "Poor".
  • 3, "Average": If B1 is 3, it returns "Average".
  • 4, "Good": If B1 is 4, it returns "Good".
  • 5, "Excellent": If B1 is 5, it returns "Excellent".
  • "Invalid Rating": This is the [default] value. If the value in B1 does not match any of the specified values (1 through 5), then "Invalid Rating" will be returned. This is excellent for error handling or unexpected inputs.






This page is protected by Google reCAPTCHA. Privacy - Terms.
 
Built using Zapof