Merging results from different Explores in the classic Explore

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

However, there may be times when your Looker developers haven't created the relationships you need or have encountered technical limitations. In these cases, Merged Results lets you combine results from different Explores (even from different models or projects) to create data tables on which to Explore and create visualizations. You can use Merged Results as a proof of concept to further develop and define your LookML projects and models.

Merging queries

To merge the results from multiple queries, follow these steps:

  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, start by preparing the primary query by following these steps:

  1. Select an Explore from the Explore menu.
  2. Select the dimensions and measures of interest from the field picker. Don't 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:

  3. Optionally, add filters for the data.

  4. Optionally, include table calculations to create ad hoc metrics.

  5. 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, add another source query by following these steps:

  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 the name of an Explore where you'll 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.

  4. 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.

  5. Optionally, include filters to narrow the data.

  6. Optionally, incorporate table calculations to create new fields based on the query fields.

  7. Optionally, click Run to see the results of the source query and to test your filters and table calculations.

  8. 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 displays which fields will be used for each merge.

  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:

  • Examine and sort the data, including drilling into the data. If you drill into the dimension used to merge the two Explores, however, Looker displays only drill fields from the primary Explore.
  • View totals. Looker calculates totals on each of the component queries and uses those totals in the merged results. Therefore, totals may appear too high, because what you are seeing are totals calculated before the results were merged. One way to avoid this is to align the filters on each query.
  • Create visualizations.
  • Pivot dimensions in the merged results by selecting Pivot from the gear menu in the dimension's column of the data table. Note that you can't pivot dimensions in the source queries.

To reuse the merged results, you can:

  • Share the results using the browser URL.
  • Bookmark the URL in your browser to run the same merged query again in the future. You can't save the merged results as a Look.
  • Save the merged results as a tile on a dashboard (see Saving your merged results to a dashboard).

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

  • Merge queries from additional Explores by clicking the Add Query button and following the same steps.
  • Edit the source queries or configure the way the queries are merged. See Editing merged results for more information.
  • Create filters by adding those filters in the source queries, either when creating and merging the queries, or by editing the queries from the Merged Results page. Note that you can't add a filter directly to the merged results.

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 or as a collection of CSV files.

Editing merged results

Once you have your merged results, you can make the following changes to your merged results:

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.

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:

  • Rename: Specify a different name to display for the query in the Merged Results window.
  • Make Primary: Make the query the base for the merged results. See the Understanding merged results section of "Joining data from multiple queries" to understand the role of the primary query.
  • Delete: Remove the query from the merged results. (If you want to add the query back into the merged results after you've deleted it, you can use the Back button in your browser.)

Editing the merge rules

When you add a query, Looker automatically finds dimensions that 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 which fields will be used to merge the queries.

You can use the Merge Rules section to change or add which fields Looker uses to merge the queries.

  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 the X if you don't want to match the data between the two dimensions.

Switching the primary query

When merging queries, you start out by creating a single query from a single Explore and then you add other queries by combining them with that first query. By default, that first query is considered the primary query, but you 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 the Understanding merged results section of "Joining data from multiple queries" for more information about the role of the primary query.

Saving your merged results to a dashboard

Once you've added your merged results query to a dashboard, you can add or apply dashboard filters to your merged results tile, rearrange the tile, edit the tile, or add new tiles to your dashboard. You can't download the data from a tile based on merged results, but you can download the dashboard as a PDF or as a collection of CSV files.

Merging queries in embedded Looks, dashboards, and Explores

You can merge queries within embedded Looks, dashboards, and Explores, if you have the appropriate permissions. To merge the query of an embedded Look with another query:

  1. Hold your pointer over the Look's title to reveal the Look's gear menu, and then click the gear menu.
  2. Select Merge Results, then follow the steps for merging queries.

To merge an embedded dashboard tile's query:

  1. Hold your pointer over the dashboard tile to review the drop-down menu for the dashboard tile.
  2. From the drop-down menu, choose Explore From Here. Looker opens the Explore for that tile's query.
  3. Click the Explore's gear menu and select Merge Results.
  4. Follow the steps for merging queries.

Notes

  • All the primary query's fields are displayed in the merged results, using the primary query's names for the fields. This means that if the primary query and an added query use different names for a matching dimension, only the primary query's dimension name will be displayed in the results.
  • Your Merged Results query may have row limits:

    • By default, the join for a Merged Results query is processed in Looker memory, and therefore each of the queries being merged is limited to 5,000 rows that can be joined (or up to 50,000 rows if a higher limit is specified by your admin). If you are joining a query that returns more than the limited rows of data, only the first number of limited rows that are returned are included in the merged results.
    • If your Looker admin has enabled the In-database merge queries Looker Labs feature, and you are merging the results from two queries that are on the same BigQuery connection, the join between two queries is performed in the BigQuery database itself. In-database merge queries are more performant and can join unlimited rows. See the In-database merge queries section of "Joining data from multiple queries" for more information.
  • For merged queries that are processed in Looker memory, Merged Results is a post-query processing feature that, if not used thoughtfully, can overtax Looker instance resources and cause your Looker instance to respond more slowly for all users. If you can't take advantage of in-database merge queries, the best practice is to define functions and logic in LookML, which generates SQL that is processed by your database. View the Optimize Looker performance Best Practices page for more information about optimizing Looker performance.

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. When needed, though, merging results is a powerful technique that lets you combine data from multiple Explores and databases.