# Case / Switch

## Excel

Excel doesn't support a specific case function but instead use an IF...ELSE statement \
&#x20;\=\~IF!\~(‹logical\_test1›, ‹when\_true1›, \~IF!\~(‹logical\_test2›, ‹when\_true2›, ‹when\_false2›))

```
=IF(C10 = "A", 1, IF(C10 = "B", 2, IF(A1 = "C", 3,0)))
```

## Tableau

\~CASE!\~ ‹field› \~WHEN!\~ ‹condition1› \~THEN!\~ ‹return1› «WHEN condition2 THEN return2 ... » \~ELSE!\~ ‹returnN› \~END.\~

```
CASE [Job Band] 
  WHEN "A" THEN 1 
  WHEN "B" THEN 2 
  WHEN "C" THEN 3 
END
```

NB. Each `WHEN` tests the *actual string* provided and compares it to the value of the target field; it does not allow logical tests e.g. `WHEN > 10 ...`. For this, use an IF...ELSE statement.

## Alteryx

\~SWITCH!\~(‹field›, ‹default\_result›, ‹condition1›, ‹return1›«, condition2, return2, ...»)

```
SWITCH([Job Band], 0, 
  "A", 1, 
  "B", 2, 
  "C", 3
)
```

## OrgVue

‹var expression› = {‹condition1›: ‹return1›«, condition2: return2, ... »}; \
&#x20;‹expression›\[‹node.field›]

```
var gradeMap = {
   "A": 1,
   "B": 2,
   "C": 3,
};
node.gradeMap[node.jobband]
```

## tSQL

\~CASE!\~ «(field)» \~WHEN!\~ ‹condition1› \~THEN!\~ ‹return1› \~ELSE!\~ ‹return2› \~END!\~

```
SELECT CASE(JobBand)
 WHEN "A" THEN 1
 WHEN "B" THEN 2
 WHEN "C" THEN 3
AS Grade
FROM EmployeesData
```

NB. If you omit the «field», the `CASE` statement will search all fields.

```
CASE
WHEN MIN(Value) <= 0 THEN 0 
WHEN MAX(Value) >= 100 THEN 1 
END
```

## Python

‹var expression› = {‹condition1›: ‹return1›,« condition2: return2, ...»}; \
&#x20;‹expression›\[‹field›]

```
gradeMap = {
   "A": 1,
   "B": 2,
   "C": 3,
};
gradeMap[jobBand]
```

NB. The above example assumes a variable has been declared for `jobBand`. For more information, go to [General > Variables](https://orgvue.gitbooks.io/formula-translator/content/general/variables.html).


---

# 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://concentra-analytics.gitbook.io/working-with-data/logical/case_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.
