User Guide Help Center Documentation User Forums Training
Looker
Merging Results from Different Explores

Explores in Looker are designed by your Looker developers to combine the data from your database tables in the best way, using defined relationships between data fields and tables. Because of this, it is best to use a single Explore to examine your data.

However, there may be times when your developers haven’t created the relationships you need, or they faced technical limitations. In these cases, Looker lets you combine data from different Explores (even from different models or projects) to create data tables and visualizations.

Using the Merged Results feature, you can create a query from an Explore, then add queries from other Explores to display the merged results in a single table. From there, you can examine the data, pivot fields, and create visualizations.

New in Looker 5.18, Merged Results is a fully supported feature that is enabled by default on your Looker instance. The feature no longer has to be enabled by an admin in Looker Labs.

Also in Looker 5.18, the Content Validator now checks and fixes field names that are referenced in dashboard tiles based on merged results.

Finally, in Looker 5.18 you can now apply dashboard filters to tiles that are based on merged query results.

Understanding Merged Results

When you merge queries, you start out by creating a single query from a single Explore, and then you add other queries onto that first query.

By default, that first query is considered the primary query. This is an important concept because when Looker matches the data to create the merged results, it matches each added query to the primary query (not to any other added query). So whenever you add a query, you need to include a dimension that can be matched to a dimension in the primary query.

Note that you can change which of the queries is used as the primary query, as described in Switching the Primary Query.

Below is an example set of queries and their merged results:

All of the primary query’s fields are displayed in the merged results, using the primary query’s names for the fields. Which means that if the primary query and an added query use different names for a matching dimension, then it is only the primary query’s dimension name that will be displayed in the results.

For those who are familiar with SQL joins, the Merged Results feature performs in a similar way as a left join: It’s as if the added query is being left joined into the primary query.

If you aren’t familiar with the idea of a left join, no worries. In practical terms, here’s why it matters which query is the primary query:

What If One Query Doesn’t Have A Matching Data Value?

Another reason the primary query is important is because of the way null values are handled in the matched dimensions:

In our example, if we switch the primary query to make the added query as the new primary query, we get the merged results shown below.

Note that now we don’t have the Maternity rows because they do not exist in our new primary query. However, now we do have the Jeans rows and those rows show NULL for the dimensions and measures that are only in the query that is added to the primary query.

What If One Query Has Multiple Rows for the Same Value?

Finally, designating the desired primary query is also important because of the way multiple rows with matching values are handled. If the added query has two or more rows with values that match a row in the primary query, the primary query row will be duplicated that number of times.

In the example below, the added query has two rows for Dresses. In the merged results, the Dresses values from the primary query appear twice, once for each of the Dresses rows from the added query:

Note that if you switch the primary query in this case, you would still have two Dresses rows, since the newly-designated primary query has two rows for Dresses. The takeaway is that when merging queries, the results may have more rows than the primary query has — but there will never be fewer rows.

Merging Queries

To merge the results from multiple queries, you need to:

  1. Create the first source query, called the primary query
  2. Add the next source query
  3. Check the merge rules for those queries and run the merge
  4. Optionally, you can:

    • Sort, pivot, and create visualizations for the results
    • Reuse and share the results using the URL
    • Modify the results by editing the source queries or adding source queries

Creating the Primary Query

To merge the results from multiple queries, you start with a beginning query, which is considered the primary query:

  1. Select an Explore from the Explore menu.
  2. Select the dimensions and measures of interest from the Field Picker. Do not pivot any dimensions during this step.

This is all you need to start merging results. However, you can also use some advanced exploring techniques to further refine your query. You can:

  1. Optionally, add filters for the data.
  2. Optionally, include table calculations to create on-the-fly metrics.
  3. Optionally, click Run to see the results of your primary query and to test your filters and table calculations.

Adding the Next Source Query

Once you’ve created your primary Explore, you can add another source query:

  1. In your Explore, click the gear icon.
  2. Select Merge Results. This will open the Choose an Explore window.
  3. In the Choose an Explore window, click on the name of an Explore where you will create your next query.

Looker opens the Explore in the Edit Query window, where you can build the new query to be merged into your primary query:

To merge queries, Looker finds dimensions in the queries whose values can be matched. Be sure that your queries contain at least one common dimension whose values can be matched exactly. For example, if both queries have a Date dimension, but one query uses “2017-10-01” as a value and the other query uses “October 2017” as a value, Looker can’t use that dimension to merge the queries.

  1. Select the dimensions and measures of interest from the Field Picker. Be sure to include at least one dimension that will exactly match a dimension in the primary query. Do not pivot any dimensions during this step.
  2. Optionally, include filters to narrow the data.
  3. Optionally, incorporate table calculations to create new fields based on the query fields.
  4. Optionally, click Run to see the results of your primary query and to test your filters and table calculations.
  5. Click Save to merge the query into your primary query.

Checking the Merge Rules and Running the Merge

Looker automatically finds the best dimensions to use for matching the queries and displays these matches in the Merge Rules section. Looker shows how each query will be merged with the primary query:

  1. Review the dimensions that Looker used to match the queries. (See Editing Merge Rules for information on changing these rules.)

  2. Click Run to see the merged query results:

Note that any table calculations from the source queries are displayed as standard dimensions in the merged results.

Using and Modifying the Merged Results

You can use the merged results to:

To reuse the merged results, you can:

If you want to modify the merged results, you can:

If you want to clear the cache and retrieve fresh results from your database, select the Clear Cache & Refresh option from the gear menu at the top right of the Merged Results window.

To download your merged results query, you can save the query to a dashboard and then download the dashboard as a PDF.

Editing Merged Results

Once you have your merged results, you still have the flexibility to edit the merged queries and the rules used to merge the queries:

Editing the Source Queries

From the Merged Results window, you can go back and edit the source queries by clicking on the query name in the left pane, or by selecting Edit from the query’s gear menu. These options take you back to the Edit Query screen:

From here you can add or remove fields, add table calculations, or change the source query’s filters. Click Save to return to your merged results.

The query’s gear menu also has these options:

Editing the Merge Rules

When you add a query, Looker automatically finds dimensions it can use to match the added query to the primary query. Each added query must have at least one dimension whose values exactly match up to a dimension in the primary query. Looker displays these matches in the Merge Rules section, showing how each added query will be merged with the primary query:

You can use the Merge Rules section to change or add the dimensions used for matching:

  1. Use the drop-down menu to see other dimension options for matching the data.
  2. If there are additional dimensions that could be used for matching, Looker displays + Add dimension. Click + Add dimension to configure an additional set of dimensions to use in the query merge.
  3. Click on the X if you don’t want to match the data between the two dimensions.

Switching the Primary Query

When merging queries, we start out by creating a single query from a single Explore, and then we add other queries onto that first query. By default, that first query is considered the primary query, but we can designate any query as the primary query by selecting Make Primary from the query’s gear menu:

Each added query must have at least one dimension whose values can be matched exactly to a dimension in the primary query.

When you switch the primary query, the merged results are likely to change. See Understanding Merged Results to understand the role of the primary query.

Saving Your Merged Results to a Dashboard

Once you create your merged results query, you can create a visualization and then use the gear menu to add the visualization to a dashboard:

  1. Click the gear menu and select Save to Dashboard.
  2. Give your new dashboard tile a title.
  3. Select the dashboard by either:
    • Navigating to an existing dashboard and clicking on it to select it, or
    • Clicking New Dashboard to create a new dashboard, then name your dashboard in the pop-up window.
  4. Click Save to Dashboard.

The merged results tile is now on your dashboard:

At this point you can rearrange the tiles, edit the tiles, or add new tiles.

Dashboard tiles based on merged results queries don’t support the CSV format for scheduling, sending, nor downloading. However, you can schedule, send, and download the dashboard as a PDF.

Conclusion

Whenever possible you should use the data from a single Explore, because your Looker developers have carefully considered how the data from different database tables should be combined together. When needed, though, merging results is a powerful technique that enables you to combine data from multiple Explores and databases.

Top