---
schema_version: "1"
id: 2ec539092749ae7cae7b732e2eda3f858a7796b56d58a646019f8c3c9b92992c
title: Simple case Operator
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/analytics/bi_dev_guide_saql/guides/reference/bi-saql-operators-case.md
canonical_url: https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-operators-case.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 7c01a73d6e1f0594dd85a9e4cc092d81cf6b324b71066130b35140ba6d1d5506
products:
  - Analytics SAQL Developer Guide
  - analytics
---

# Simple case Operator

Use `case` in a `foreach` statement to assign different field values in different situations. `case` supports two syntax forms: searched case and simple case. This section explains simple case.

## Syntax

```nolang

case
  primary_expr
  when test_expr then result_expr
  [when test_expr2 then result_expr2 ]
  [else default_expr ]
end
```

_case...end_ opens and closes the case operator.

_primary_expr_ is any expression that takes a single input value and returns a single output value. May contain values, identifiers, and scalar functions (including date and math functions). The expression can return a number, string, or date.

_when...then_ defines a conditional statement. A `case` expression can contain one or more conditional statements.

_test_expr_ is any expression that takes a single input value and returns a single output value. May contain values, identifiers, and scalar functions (including date and math functions). The expression must return the same data type as _primary_expr_.

_result_expr_ is any expression that takes a single input value and returns a single output value. May contain values, identifiers, and scalar functions (including date and math functions). The expression must return the same data type as _`primary_expr`_.

_else default_expr_ (optional) is any expression that takes a single input value and returns a single output value. May contain values, identifiers, and scalar functions (including date and math functions). The expression can return a number, string, or date.

## Usage

Statements are evaluated in the order that they are given. If _test_expr_ returns `true`, the corresponding _result_expr_ is returned. You can specify any number of `when`/`then` statements.

You can use `else` to specify a default expression. For example, if no industry is specified then use the string "No Industry Specified". If you don't specify a default statement then `null` is returned.

You can use `case` expressions in `foreach` statements. You cannot use `case` in `order`, `group`, or `filter` statements.

## Example

Suppose that you want to create a dimension that displays the meaning of industry codes. Use `case` to parse the Industry_Code field and specify the corresponding string.

```nolang
q = foreach q generate Amount as 'Amount', 'Industry_Code' as 'Industry_Code', (case 'Industry_Code'
      when 541611 then "Consulting services"
      when 541800 then "Advertising"
      when 561400 then "Support services"
      else "Unspecified"
end) as 'Industry';
```

The resulting data displays the meaning of industry codes:

![Derived dimension shows time to win](https://developer.salesforce.com/media/bi_dev_guide_saql/bi_saql_caseIndustry.png)

## Handling Null Values

In general, `null` values can’t be compared. When _ primary_expr_ or _test_expr_ evaluates to `null`, the _default_expr_ is returned. If no default expression is specified, `null` is returned.

**See Also**

- [Speed Up Queries with Dataflow Transformations](https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-performance-dataflow-transformations.md)
