Skip to main content
Refer to the Filters documentation for information about defining curated filters directly in your model YAML.
Omni allows parameterization of SQL using the Mustache template engine, which can be used in the definition of both views and fields. This is perhaps best understood through examples. Templated filters can inject dynamic text into a SQL query, often a dimension or fact table. Our syntax requires an opening and closing reference around the dynamic input, using {{# }} to open, and {{/ }} to close to dynamic sections. Inside the braces, you use the name of the object, usually of the form view.field_name.filter (the word “filter”). This will correspond to a filter_only field in the view (see examples below). Inside the pair of braces, you will include the lookup value.

Setting default values

Default values can be set using {{^ }}default_value_clause{{/ }} immediately after the existing templated filter syntax. For example, the following would use a default filter of name like 'foo':

Examples

Any YAML parameter that expects a string must be wrapped in double quotes if the leading character has special meaning in YAML. For example, sql: {{ view.field_name.filter }} would need to be sql: "{{ view.field_name.filter }}" to avoid validation errors.

Parameterized WHERE clause in views based on a SQL query

This simple example allows a query-view to be parameterized. This example uses a filter-only field (see more on this in the dedicated section below), but can also reference a field in the view itself.
The filters will appear as filter-only fields in the field picker, in their own section under the measures section. These can then be used as normal filters, and the specified expression is inserted in place.

Time frame switcher

In many cases, the UI-based time frame switcher control may be a better path.
A field of dynamic granularity can be constructed such that a single filter on a dashboard swaps the granularity for multiple time series in one. By editing the .view file, it is necessary to add a dynamic dimension and a filter. In the example below, replace all references to created_date with the appropriate date field and order_items with the fully qualified view reference.
This timeframe_selector filter can then be used either in workbooks or on dashboards across multiple tiles to update them all at once.

Conversion rates

A common analytical pattern is to compare conversion rates with 1, 3, 7, 30, or however many days. For the more static form, one might do something like this:
This is very useful, but requires that measures be created for 1, 3, 7, 30, etc. -day conversion rates. We can add a dynamic option:

Dynamically filter active subscriptions using date range (SCD2)

If you have data that shows that defines the dates for the beginning of a subscription and the end of a subscription, this example allows end users the ability to filter for active subscriptions during a dynamic time frame. This utilizes Omni’s out of the box time frame selector, so some dates selections will not work well such as “On Day of Month”, but any value that is a range of dates or a specific date will return the active subscriptions during that time.

Dynamically switching database table in a query

In some cases, users may need to be able to quickly switch between multiple tables when performing an analysis. For example, tables with similar data structures but differing data, such as different time grains. Note: The approach described below should be placed in a new view. You can add a view in the model IDE by clicking File > New View.
For some databases, such as Snowflake, you will need to wrap the {{filters.your_table_name.filter_field.value}} in IDENTIFIER() to cast from a string to a SQL query-able value.

Dynamically filter total count

Dynamically filter a count down to just the count for a specific value. This allows for creating visualizations where you compare the overall count to the count filtered by the dynamic value on a single visualization.

Dynamic period-over-period with custom date range

Having the ability to create custom date ranges in period over period allows for flexibility to select any date range within each period to compare values against. In the below example, there is a view file of demo real estate data where two filter-only fields have been added to create the custom date range selectors that will then be used to filter against the added measures that sum the sales_amount if the date matches the date selected in the custom filter_only field.

Filter-only fields

For specific filter syntax, like measure filters see here.

aliases

Similar to table level aliases, occasionally a field name may change in your database, which can cause content to break. To fix this, we can add aliases: to the field in question pointing references from the old field name to the updated field name, restoring content and eliminating content related errors. This behaves similar to table level aliases, as shown

bind_to

A list of field names that the filter-only field’s filter expression should be applied to. When a filter is applied to this filter-only field, the filter expression will be applied to each field in this list. Filters on dimensions will go into the WHERE clause, while filters will go into the HAVING clause.

default_filter

  • default_filter will automatically populate the filter value in the templated object
  • This is often paired with filter_single_select_only and suggestion_list when a single-selection is required
  • For setting the filter arguments, use the filter syntax

description

  • Metadata about the field, made available in the workbook/dashboard table UI upon hovering over a field with a description, or on right click from the field picker
  • Omni expects unquoted text (quotes will be removed / ignored)

display_order

  • Omni expects a whole number
  • This will override the sort order for the field picker, inside the field’s grouping (i.e. inside a given view)
    • display_order will supersede alphabetical sorting
  • For example, if the two fields above in users are given display_order: they will float to the top of the field list in users, and the remaining fields would be sorted alphabetically
  • To rearrange views, display_order can be used at the view level
  • For fields inside groups using group_label, the group will be ranked with the min of all the fields in the group (i.e. if there are 3 fields with display_order of 4, 5 and {empty}, the group will have a display_order of 4)

filter_single_select_only

  • This argument will require the filter field to use a choose-one dropdown rather than the default flexible filter modal
  • Recommended with templated filters that require one-and-only-one object

group_label

  • This will nest a group of fields in the field picker for curated organization
  • Omni expects unquoted text (quotes will be removed / ignored)
  • Note measures and dimensions will still be in separate sections in the field picker under each view
  • Fields can be nested under timeframes using the group label - the text rather than the field should be used (i.e. Created At not created_at)

hidden

  • Remove the field from the UI. Still referenceable in the model, but hidden in the workbook UI.
  • Expects ‘true’ or ‘false’

ignored

Likely should not be used with filters, can just delete or comment out if it’s not desired in the model

label

  • Label will override the field name for all UI appearances of the field
  • Omni expects unquoted text (quotes will be removed / ignored)

required_access_grants

You can also conditionally allow access by using pipes (|) and ampersands (&) to create OR and AND conditions.

suggestion_list

  • Suggestion list will explicitly set the suggestions on

suggest_from_field

  • This argument can be used to populate a filter with another field’s values
  • Commonly used with the filter is injected in sql with a corresponding modeled field

suggest_from_topic

  • This needs to be paired with suggest_from_field and can tune the specific topic (ie access-filters and default filters) for a given suggestion

type

  • Currently, filter-only fields can only be defined in the IDE. They require a name, and a type. The accepted types for a filter-only field are:
    • boolean
    • column (returns unquoted text, can be used to substitute in column names in query views)
    • number most common
    • string most common
    • timestamp most common

view_label

  • This will nest a given field under a different view than it’s default parent view, for example, grouping user_facts fields under the users view for better organization and discovery
  • Note that filters will always be below dimensions and measures
  • Sometimes can be valuable to pull all filters into a separate pseudo-view, would do that with the view argument as seen here

Parameters

Parameters can be used in Omni in tandem with filter-only Fields. The value of a filter-only field can be referenced using the structure {{filters.table_name.field_name.value}}, and can be used in definitions for other fields. When that filter-only field is applied to a workbook or dashboard, it can be used to change the value of the parameter field, and thus interact with the query accordingly. Consider using the filter_single_select_only argument when using a string filter-only field to parameterize some selector.

Dynamic date range example

Users can reference the start or end range of a date filter using the structure {{filters.table_name.field_name.range_start}} and {{filters.table_name.field_name.range_end}}.

Dynamic date range comparison example

This example creates a pair of filtered measures using templated filters to select specific dates.

Dynamic field examples

This example pipes columns table.field1 or table.field2 into the dynamic_dimension. For this dynamic dimension, the filter only field requires the use of type: column. Note this injects the SQL dialect’s column naming convention and will only pass SQL validation if the correct database column reference is defined for the value subparameter (e.g. in Snowflake the scoped column names would need to be capitalized). Consider including the suggest_from_field subparameter in the filter only field to generate a list of values from the database’s metadata table.
Here we’ve built a Snowflake Cortex dynamic column that can call a model based on the dynamic_model specified. The filter is set as single-select, with descriptions on each model to help the end user. This value is piped into the Cortex call to select the given model for analysis using filters.states.dynamic_model.value.

Dynamic date part example

This pattern creates a fact table to be requeried or aggregated using a template filter to set the date part (here BQ SQL). Note we cannot current inject unquoted strings into the SQL block, but we can instead handle with a CASE statement.

Self-referential building

We have a few handy parameters that can be leveraged in your models to build joins, dimensions, and measures based on what is present in the query. The format for calling these parameters is and they will evaluate to TRUE or FALSE:
  • {{ view_name.field_name.in_query }} OR {{ view_name.in_query }}
  • {{ view_name.field_name.is_selected }}
  • {{ view_name.field_name.is_filtered }}

in_query

This will look for the presence of a specific field OR view in the SELECT or WHERE clause of a query.

is_selected

This will look for the presence of a specific field in the SELECT clause of a query.

is_filtered

This will look for the presence of a specific field in the WHERE clause of a query. Example of conditional join using in_query
Example of creating measure using is_selected
You can read more about this pattern in our community article.