Models are a fundamental building block in Metabase. Models curate data from another table or tables from the same database to anticipate the kinds of questions people will ask of the data. You can think of them as derived tables, or a special kind of saved question meant to be used as the starting point for new questions. You can base a model on a SQL or query builder question, which means you can include custom, calculated columns in your model.
Models:
For a deep dive on why and how to use models, check out our Learn article on models.
You can use models to:
The idea with models is to give other people a good “starting point table” that makes it easier to answer any questions they have about the subject being modeled.
First, search for models that already exist. If you can’t find one that meets your needs, you can create a model like so:
Metadata is the secret sauce of models. When you write a SQL query, Metabase can display the results, but it can’t “know” what kind of data it’s returning (like it can with questions built using the query builder). What this means in practice is that people won’t be able to drill-through the results, because Metabase doesn’t understand what the results are. With models, however, you can tell Metabase what kind of data is in each returned column so that Metabase can still do its drill-through magic. Metadata will also make filtering nicer by showing the correct filter widget, and it will help Metabase to pick the right visualization for the results.
If you only set one kind of metadata, set the Column type to let Metabase know what kind of data it’s working with.
What people will see as the column’s name.
A place to write helpful context for the column.
For models based on SQL queries, you can tell Metabase if the column has the same type as an existing database column.
You can set the column type. The default is “No special type”. Be sure to set the Column type so people can interact with the results.
You can specify whether a column should appear in the table view, or just in a detail view (when you click on the entity/primary key for the row).
You can edit the model’s query by clicking on the down arrow next to the model’s name and clicking on Edit query definition. When you’re doing editing, be sure to save your changes. Unlike questions, which prompt you to save as a new question, any changes here will overwrite the existing model. If you want to create a new model from an existing model, select Duplicate this model from the model sidebar (the icon of two overlapping squares).
See asking questions.
You can refer to a model in a SQL query just like you can refer to a saved question:
SELECT * FROM {{#1}}
Or as a common table expression (CTE):
WITH model AS {{#3807}}
SELECT *
FROM model;
Just like with saved questions, you can click on the model name with the down arrow to bring up the model’s sidebar, then click on History at the bottom to bring up a list of the changes made to the model over time, and by whom.
⚠️
Model verification
This feature is only available on Pro and Enterprise plans (both self-hosted and on Metabase Cloud).
Just like with a question, admins can verify models. Verifying a model will give it a check mark to let others know an admin vetted the model. If anyone makes any changes to the model, the check mark will disappear. An admin will have to verify the question again to restore the check mark.
If you’re having trouble with your model, go to the Models troubleshooting guide.