A common issue organizations have is providing all necessary data, without drowning the user in irrelevant data. Consider the following situation:
The Marketing team and Finance team share a lot of the same data. However, the Marketing team has a lot of data that is irrelevant to the Finance team. The Finance team should be able to choose to view only the data relevant to them, without being overwhelmed with marketing-specific content.
We can use the LookML parameters extends
and include
to make this happen.
Take these two models as an example:
- The Finance model
- The Marketing model
Our finance.model.lkml
file might look as follows:
connection: "default_name" include: "/views/*.view.lkml" include: "/dashboards/*.dashboard.lkml" # this explore will not be accessible - it is just a template explore: order_items { view_name: order_items from: order_items extension: required join: orders { type: left_outer sql_on: ${order_items.order_id} = ${orders.id} ;; relationship: many_to_one } } explore: order_items_finance { extends: [order_items] }
While this is enough for the Finance model, the Marketing team actually needs more user-specific information, to identify cohorts by referral source and age demographics.
We cannot extend a model file, and we cannot include a model file in another model file. So if we want to reuse and extend an Explore across models, we can create a separate Explore file, then include that Explore file in different model files and extend the Explore from each of the model files. To do this, we first move our base Explore into its own Explore file. Here are the contents of the order_items.explore.lkml
file:
include: "/views/.view.lkml" # this explore will not be accessible - it is just a template explore: order_items { view_name: order_items from: order_items extension: required join: orders { type: left_outer sql_on: ${order_items.order_id} = ${orders.id} ;; relationship: many_to_one } }
Since we've moved this Explore out of our finance.model.lkml
file, we need to use include
in the model file to bring the Explore back in. Once we include the order_items.explore.lkml
file, we can extend the Explore in our model. So here is what our finance.model.lkml
file looks like now that we've included the Explore and extended it:
connection: "default_name" include: "/views/.view.lkml" include: "/dashboards/*.dashboard.lkml" include: "/explores/order_items.explore.lkml" explore: order_items_finance { extends: [order_items] }
Now, in our Marketing model file, we'll include the order_items.explore.lkml
file, and then extend the Explore to suit our Marketing users:
connection: "default_name" include: "/explores/order_items.explore.lkml" explore: order_items_marketing { extends: [order_items] join: users { type: left_outer sql_on: ${orders.user_id} = ${users.id} ;; relationship: many_to_one } }
Now there is only one Explore showing under each model, and the Finance users won't see the Marketing fields.
Note: In the Marketing file, avoid using include: "*.view.lkml"
. This can lead to certain files being included multiple times.