# SWITCH

The **SWITCH** function evaluates an expression against a list of values and returns the result corresponding to the first matching value. If no match is found, an optional default value is returned.

### Syntax

```javascript
SWITCH(expression, val1, res1, val2, res2, ..., val_n, res_n, default)
```

### Arguments

* *expression*: The expression to evaluate.
* *val1, val2, … val\_n*: The values to compare against the expression.
* *res1, res2, … res\_n*: The result to return for each matching value.
* *default* (Optional): The value to return if no match is found.

### **Return value**

Returns the result corresponding to the first matching value. If no match is found, returns the *default* value (if specified).

### **Example**

<pre class="language-javascript"><code class="lang-javascript"><strong>SWITCH(Sub-Category, "Bookcases", 4.55, "Chairs", 2.67, "Tables", 2.81, "Art", 1.35, 
</strong><strong>"Paper", 3.79, "Machines", 10.55, "Envelopes", 1.23, "Storage", 2.53, 0)
</strong></code></pre>

Evaluates the *Sub-Category* value and returns the corresponding numeric value for each match; if no match is found, returns 0.

<figure><img src="/files/V19wt6TFmrErzi2nZBwc" alt=""><figcaption></figcaption></figure>

### **Excel equivalent**

[SWITCH](https://support.microsoft.com/en-us/office/switch-function-47ab33c0-28ce-4530-8a45-d532ec4aa25e)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.fabricplan.com/planning-sheets/formula-syntax/conditional-statements/switch.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
