Data and Business Intelligence Glossary Terms

A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
V
W
X

Variable

What is a variable?

A variable is any value in a program or query that can change. In SQL, declaring a variable allows you to temporarily store a single value while running a query.

Parameters are a type of variable, but not all variables are parameters. When people talk about parameters, they’re usually referring specifically to variables that get modified by the end user of a dashboard or report, rather within the text of a query itself.

Example variable in Metabase

In Metabase, variables are placeholders in SQL queries for values that people can change without needing to rewrite the query itself. Using variables allows you to filter your data, often by adding a filter widget above that question in the SQL editor.

Variables get enclosed in double braces, like this: {{variable_name}}. In the example below, we create a variable to filter based on the Source field in the Sample Database’s People table:

SELECT *
FROM people
WHERE source = {{source}}

When you include a variable in your query (in this case {{source}}), Metabase adds a filter widget above the SQL editor, like in figure 1. Since the filter widget maps to the variable we created, we can plug different values into it to filter for different sources.

<em>Fig. 1</em>. The filter widget above the query editor maps to the variable wrapped between double braces.
Fig. 1. The filter widget above the query editor maps to the variable wrapped between double braces.

Related terms

Further reading

Thanks for your feedback!