> ## Documentation Index
> Fetch the complete documentation index at: https://docs.omni.co/llms.txt
> Use this file to discover all available pages before exploring further.

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback:

POST https://docs.omni.co/feedback

```json
{
  "path": "/modeling/models/constants",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.

</AgentInstructions>

# constants

> Define reusable string values that can be referenced throughout your model.

Constants are string values that can be defined once in a [model file](/modeling/models) and referenced throughout your model using `@{constant_name}` syntax.

Constants are resolved before other template processing (Mustache and field references) when a query executes or a link renders, making them ideal for values that need to be centrally managed and consistently applied across your model. For example:

* Database schema names that may differ between environments
* Common URL patterns for data links
* Repeated string values that you want to maintain in a single location
* Configuration values that can be dynamically referenced

Constants are also inherited by [shared extension models](/modeling/develop/shared-extensions).

## Syntax

```yaml theme={null}
constants:
  <constant_name>:
    value: <string_value>
```

## Properties

<ParamField path="constants" type="object">
  A map of constant definitions where each key is the constant name. Names must be unique within the model.

  <Expandable title="constant_name properties" defaultOpen="true">
    <ParamField path="value" type="string" required>
      The string value for the constant. Can contain fully-scoped field references using `${}` syntax, which will be resolved when the constant is used during query execution or link rendering. For example, `${users.country}`
    </ParamField>
  </Expandable>
</ParamField>

## Examples

### Dynamic schema reference

Use constants to reference schema names that may vary across environments. Define the constants in the model file:

```yaml title="Model file" theme={null}
constants:
  base_schema:
    value: analytics_prod
  staging_schema:
    value: analytics_staging
```

And then reference the constants, such as in the following view file:

```yaml title="View file" theme={null}
sql: |
  SELECT *
  FROM @{base_schema}.users
```

### Dynamic links with field references

Create link patterns that include field references. Define the constants in the model file:

```yaml title="Model file" theme={null}
constants:
  google_search:
    value: "https://www.google.com/search?q=${users.country}"
  user_profile:
    value: "https://example.com/profile/${users.user_id}"
```

And then reference the constants in fields, such as the following dimensions:

```yaml title="Dimensions in a view" theme={null}
dimensions:
  country:
    sql: country
    link: "@{google_search}"
  user_id:
    sql: user_id
    link: "@{user_profile}"
```

### Reusable format patterns

Constants are often used with the `format` parameter on dimensions and measures. Reference a constant with `@{constant_name}` inside the format string (including inside [conditional format](/modeling/models/format-values#conditional-formats) branches).

<Note>
  For standard currency and number display, use a [named format](/modeling/models/format-values#named-formats) like `usdcurrency_2` or `percent_1` directly. Constants are most valuable for **custom** Excel-style patterns that appear in several fields.
</Note>

```yaml title="Model file" theme={null}
constants:
  compact_time:
    value: 'm:ss "min"'
  margin_display:
    value: '#,##0.00 "bps"'
```

```yaml title="View file" theme={null}
measures:
  avg_duration:
    sql: '"duration_secs"'
    aggregate_type: avg
    format: "@{compact_time}"
  margin:
    sql: '"margin_bps"'
    aggregate_type: avg
    format: "@{margin_display}"
```

See [Model constants in format strings](/modeling/models/format-values#constants-in-formats) on the formatting page for more detail.
