Skip to main content
This guide walks through building a query view in Omni that takes sparse key-value data and fills in the gaps so the result can be cleanly pivoted in a workbook. It covers setting up the SQL using a cross join, wiring up a scoped templated filter, and defining the YAML dimensions and measures that make pivoting work. This is especially relevant if:
  • Your source table has rows shaped like entity_id | attribute_name | attribute_value, and not every entity has a row for every attribute name
  • You want to pivot attribute names into columns in an Omni workbook without missing rows collapsing silently
  • You need a dynamic filter that scopes the query to a subset of data (for example, by a parent ID) and populates its dropdown from the database

Understanding the pattern

If your data looks like this: A direct pivot would silently drop the missing combinations. The cross-join pattern fills them in first, so the result looks like this before pivoting: The query view does this by cross-joining all distinct entity IDs against all distinct attribute names, then left-joining back to the source table to pick up values where they exist.
The fill_fields query view parameter solves a related but different problem. It fills missing values from an enumerated or date series. The cross-join approach here is for cases where both the entities and attributes are dynamic and sourced from the data itself.

Requirements

To follow the steps in this guide, you’ll need:
  • Modeler or Connection Admin permissions on the model
  • The fully qualified path to your table (DATABASE.SCHEMA.TABLE_NAME)
  • A table with sparse key-value rows
    This guide uses Snowflake to walk through examples. If using a different database, you may need to adjust the SQL to your database’s syntax.

Building the query view

1

Confirm the table path

Before you start working in Omni, confirm the fully qualified path to your table in Snowflake. If you’re unsure, run the following in Snowflake:
Then confirm the exact database and schema:
Your full table path will be: DATABASE.SCHEMA.TABLE_NAME
2

Create the query view file

Query views can be created two ways in Omni: through the model IDE (recommended), or from a workbook.
3

Add the YAML template

Paste the following template into your query view file. Every value in ALL_CAPS is a placeholder you’ll replace with a real value in the next step — except CREATED_AT, which is an optional column you can rename or remove (see the inline comment in the template).
The placeholder table in the next step covers all substitutions. For example, if your scoping column is ACCOUNT_ID, replace every instance of SCOPE_COLUMN with ACCOUNT_ID and rename scope_id_dim to account_id_dim everywhere it appears — including in suggest_from_field.
your_query_view.query.view
Setting a default filter value is important. Without one, the cross-join CTEs will scan the entire source table on first load.
4

Replace placeholders in YAML

Replace each placeholder in the YAML using the table below:Once all placeholders are replaced, your query view is ready to test.
5

Enable pivoting in the workbook

Omni requires at least one measure on a query to enable pivoting, which is why this view defines attribute_value as a max measure.
This pattern assumes at most one value per entity + attribute (+ scope) combination. If your source has multiple rows for the same combination, the max measure returns only the highest value lexically and drops the others. De-duplicate upstream or change the aggregation if that isn’t what you want.
Once the query view is saved and the model is valid:
  1. Open a workbook and select your query view as the data source.
  2. Add Entity ID as a dimension.
  3. Add Attribute Value (Aggregated) as a measure.
  4. Right-click Attribute Name in the field browser and select Pivot.
Each unique attribute name will become its own column, with NULL shown where no value existed.To change the scope (for example, to view a different parent ID), apply the Scope Filter filter-only field that appears in the field browser under this view’s filters.
6

Promote to the shared model

Once you’ve confirmed the query view works as expected in the workbook, promote it to make it available across all workbooks.In a published workbook, click Model > View & promote changes, review the changes, and click Promote to shared.

Next steps