You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _docs/master/dashboards/filters.md
+70-33Lines changed: 70 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,30 +16,15 @@ redirect_from:
16
16
17
17

18
18
19
-
Have you ever found yourself in a situation where it seems like you need to create nearly identical copies of the same dashboard, with just one different variable? Maybe you have an Earnings dashboard, but you want to see the data for each city your business is in, or maybe you have a KPI dashboard that you want to see broken out by month.
19
+
Instead of creating duplicate dashboards to show different cuts of the same data (like a different dashboard for each quarter), you can add filter or parameter widgets to let people change _what_ data is displayed (filter the data), or _how_ its displayed (parameterize the data).
20
20
21
-
Instead of creating duplicate dashboards, you can add filter or parameter widgets to let people change variables for cards on a dashboard.
21
+
## Filter and parameter widgets
22
22
23
-
## Adding a filter or parameter
24
-
25
-

26
-
27
-
- Click the **pencil icon** to enter dashboard editing mode.
28
-
- Click the **filter icon** that appears in the top-right to add a filter.
29
-
- Select a [filter type](#filter-and-parameter-types)
30
-
-[Connect your filter or parameter widget to dashboard cards](#connecting-a-filter-or-parameter-widget-to-dashboard-cards) to one or more dashboard cards on any or all tabs.
31
-
-[Configure your filter](#editing-a-filter)
32
-
-**Save** your changes.
33
-
34
-
Metabase will display the filter only if the filter is connected to a card on the current dashboard tab.
35
-
36
-
## Filter and parameter types
37
-
38
-
The type of filter or parameter widget you choose determines how the widget works, including which fields you'll be able to filter your cards by.
23
+
There are two basic types of widgets you can add. The type of filter or parameter widget you choose determines how the widget works, including which fields you'll can connect to the widget.
39
24
40
25
### Filter widgets
41
26
42
-
**Filters** determine what data to show. For example, a date filter might show only data from the last 30 days, or a category filter might show only specific product categories.
27
+
**Filters** determine _what_ data to show. For example, a date filter might show only data from the last 30 days, or a category filter might show only specific product categories.
43
28
44
29
-[Date picker](#date-picker-filters)
45
30
-[Location](#location-filters)
@@ -50,13 +35,45 @@ The type of filter or parameter widget you choose determines how the widget work
50
35
51
36
### Parameter widgets
52
37
53
-
**Parameters** determine how to show the data. The time grouping parameter, for example, changes the granularity of time-based visualizations (like showing data by month instead of by day) without removing any data points.
38
+
**Parameters** determine _how_ to show the data. The time grouping parameter, for example, changes the granularity of time-based visualizations (like showing data by month instead of by day) without removing any data points.
54
39
55
40
-[Time grouping](#time-grouping-parameter)
56
41
42
+
## Adding a filter or parameter widget
43
+
44
+

45
+
46
+
1. Click the **pencil icon** to enter dashboard editing mode.
47
+
2. You can add a filter or parameter widget to:
48
+
49
+
-**The whole dashboard**. Metabase will only display dashboard-level widgets if they're connected to a card on the current tab.
50
+
-**Heading cards**. Not text cards, only [heading cards](./introduction#adding-headings-or-descriptions-with-text-cards). Can only be connected to cards on the current tab.
51
+
-**Question cards**. Can only be connected to cards on the current tab.
52
+
53
+
Go to where you want to add a filter and click the **filter icon**.
54
+
3. Select a [filter type](#filter-and-parameter-types).
55
+
4.[Connect your filter or parameter widget to dashboard cards](#connecting-a-filter-or-parameter-widget-to-dashboard-cards) to one or more dashboard cards. Only dashboard-level widgets can be connected to cards on multiple tabs.
56
+
5.[Configure your filter](#editing-a-filter).
57
+
6.**Save** your changes.
58
+
59
+
Metabase will display the filter only if the filter is connected to a card on the current dashboard tab.
60
+
61
+
### When to add a widget to a heading or card
62
+
63
+
These are just rules of thumb to keep the user experience predictable. Do whatever works for your use case.
64
+
65
+
By default, you should add widgets to the dashboard itself.
66
+
67
+
If, however, your dashboard grows larger, and it doesn't make sense to break the dashboard up into multiple dashboards, you can add widgets to headings and cards so people can filter in place as they scroll through sections. In these cases, you should scope the effects of a heading widget to the section immediately below. Filters on cards should generally only update the card itself.
68
+
69
+
If you want tab-specific widgets, you could either:
70
+
71
+
- Add them to the dashboard itself, but only connect the widget to cards on a specific tab.
72
+
- Use a heading filter.
73
+
57
74
## Date picker filters
58
75
59
-
When picking a Time filter, Metabase will prompt you to pick a specific type of date picker widget:
76
+
When picking a Date picker filter, Metabase will prompt you to pick an operator:
60
77
61
78
- Month and Year
62
79
- Quarter and Year
@@ -65,19 +82,17 @@ When picking a Time filter, Metabase will prompt you to pick a specific type of
65
82
- Relative Date
66
83
- All Options
67
84
68
-
Single Date and Date Range will provide a calendar widget, while the other options all provide slightly different dropdown interfaces for picking values. To get a widget that's just like the time filter in the query builder, choose All options.
85
+
Single Date and Date Range will provide a calendar widget, while the other options all provide slightly different dropdown interfaces for picking values. To get a widget that's just like the date picker in the query builder, choose All options.
69
86
70
87
## Time grouping parameter
71
88
72
89

73
90
74
-
You can add a time grouping widget to a dashboard to change how charts are grouped by time. For example, you may want to look at the time series charts grouped by month by default, but give people the option to view the results by other groupings: by week, by quarter, and so on.
75
-
76
-
> Time grouping parameter widget can only be connected to questions built with the [graphical query builder](../questions/query-builder/editor).
91
+
You can add a time grouping widget to a dashboard to change how charts are grouped by time. This widget won't filter the data; it'll change how Metabase displays the data. For example, you may want to look at the time series charts grouped by month by default, but give people the option to view the same results by other groupings: by week, by quarter, and so on.
77
92
78
93
This widget doesn't filter data in the charts; the widget just changes the time granularity for any cards that have a datetime field connected to the widget.
79
94
80
-
You can group by:
95
+
Grouping options include:
81
96
82
97
- Minute (or minute of hour)
83
98
- Hour (or hour of day)
@@ -87,6 +102,8 @@ You can group by:
87
102
- Quarter (or quarter of year)
88
103
- Year
89
104
105
+
To connect a time grouping widget to a SQL question, you'll need to insert time grouping parameters in your code. See [time grouping parameters](../questions/native-editor/time-grouping-parameters).
106
+
90
107
## Location filters
91
108
92
109
There are four types of Location filters to choose from:
@@ -96,10 +113,21 @@ There are four types of Location filters to choose from:
96
113
- ZIP or Postal Code
97
114
- Country
98
115
116
+
Additionally, you can select an operator for the location filter:
117
+
118
+
-**Is**. Select one or more values from a list or search box. Use **Is** when you just want to plug a value into a variable. For multiple values, the card must be either a question built using the query builder, or a native/SQL question using a [field filter](../questions/native-editor/sql-parameters#field-filter-variables).
119
+
-**Is not**. Exclude one or more specific values.
120
+
-**Contains**. Match values that contain the entered text.
121
+
-**Does not contain**. Filter out values that contain the entered text.
122
+
-**Starts with**. Match values that begin with the entered text.
123
+
-**Ends with**. Match values that end with the entered text.
124
+
99
125
## ID filter
100
126
101
127
The ID filter provides a simple input box where you can type the ID of a user, order, etc.
102
128
129
+
You can give people the option to pick one value or multiple values.
130
+
103
131
## Number filter
104
132
105
133
You can choose from:
@@ -114,21 +142,25 @@ You can choose from:
114
142
115
143
A flexible filter type that will let you create either a dropdown menu or an input box to filter on any category field in your cards. Options include:
116
144
117
-
-**Is**. Select one or more values from a list or search box. Use **Is** when you just want to plug a value into a variable. For multiple values, the card must be either a question built using the query builder, or a native/SQL question using a [field filter](../questions/native-editor/sql-parameters#the-field-filter-variable-type).
145
+
-**Is**. Select one or more values from a list or search box. Use **Is** when you just want to plug a value into a variable. For multiple values, the card must be either a question built using the query builder, or a native/SQL question using a [field filter](../questions/native-editor/sql-parameters#field-filter-variables).
118
146
-**Is not**. Exclude one or more specific values.
119
147
-**Contains**. Match values that contain the entered text.
120
148
-**Does not contain**. Filter out values that contain the entered text.
121
149
-**Starts with**. Match values that begin with the entered text.
122
150
-**Ends with**. Match values that end with the entered text.
123
151
152
+
You can also select how people should filter on this column:
153
+
154
+
- Dropdown list
155
+
- Search box
156
+
- Input box
157
+
124
158
## Boolean filter
125
159
126
160
A boolean filter allows people to filter data based on true/false values.
127
161
128
162
## Connecting a filter or parameter widget to dashboard cards
129
163
130
-
Dashboard widgets apply across all [dashboard tabs](./introduction#dashboard-tabs), though they'll only be displayed when a tab has cards connected to the widget.
131
-
132
164
For each widget that you add, you'll need to tell Metabase which column the filter should update for each card.
133
165
134
166
Click on a card's dropdown menu to select the field that you want the widget to filter on.
@@ -137,6 +169,11 @@ Here we've wired up a Text filter to the "Event types" card, telling Metabase th
137
169
138
170

139
171
172
+
Which cards you can connect a filter or parameter widget to depends on:
173
+
174
+
- Whether the question card has the relevant field.
175
+
- Where the widget is located: on the dashboard, heading card, or question card. Only dashboard widgets can be connected to cards across all [dashboard tabs](./introduction#dashboard-tabs). Widgets on heading and question cards are restricted to the cards on their respective tabs.
176
+
140
177
## Auto-connecting filters to cards
141
178
142
179
If there are other cards that also have the field you select, Metabase will offer to automatically connect the filter to those cards too (including to relevant cards on other tabs). If you later add a card with the selected field, Metabase will also try to connect that filter to the new card.
@@ -145,9 +182,9 @@ To undo this auto-connecting of cards, click on the toast that pops up when Meta
145
182
146
183
## Filtering dashboards with native/SQL questions
147
184
148
-
If you're trying to connect a filter to a card with a native/SQL questions, you'll need to [add a variable or field filter to your query](../questions/native-editor/sql-parameters). For an in-depth article, check out [Adding filters to dashboards with SQL questions](/learn/metabase-basics/querying-and-dashboards/sql-in-metabase/filters).
185
+
For filters, you'll need to [add a variable or field filter to your query](../questions/native-editor/sql-parameters).
149
186
150
-
You can't connect a time grouping parameter widget to a card with a SQL question.
187
+
For parameters, check out [Time grouping parameters](../questions/native-editor/time-grouping-parameters).
151
188
152
189
## Wiring up dashboard filters to text cards
153
190
@@ -201,8 +238,8 @@ A list of all of the possible values in a column. People can use checkboxes to s
201
238
202
239
If you're not seeing the **Dropdown list** option, and your dashboard filter is based on a column from a:
203
240
204
-
- Table or GUI model: an admin will need to [enable the dropdown widget](../data-modeling/metadata-editing#changing-a-search-box-filter-to-a-dropdown-filter) for that column from Metabase's **Admin settings**.
205
-
- SQL model: go to your [model's metadata settings](../data-modeling/models#add-metadata-to-columns-in-a-model), find your column, and set the **Database column this maps to**.
241
+
- Table or model built with the query builder: an admin will need to [enable the dropdown widget](../data-modeling/metadata-editing#changing-a-search-box-filter-to-a-dropdown-filter) for that column from Metabase's **Admin settings**.
242
+
-Model built with a SQL query: go to your [model's metadata settings](../data-modeling/models#add-metadata-to-columns-in-a-model), find your column, and set the **Database column this maps to**.
Copy file name to clipboardExpand all lines: _docs/master/dashboards/linked-filters.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -63,7 +63,7 @@ Metabase uses database column metadata to populate values for linked filters, wh
63
63
64
64
- You can't create linked filters on custom columns.
65
65
66
-
- Native/SQL questions must have a [field filter](../questions/native-editor/sql-parameters#the-field-filter-variable-type) variable in order to be linked. Basic SQL variables aren't connected to database columns, so they won't work for linked filters.
66
+
- Native/SQL questions must have a [field filter](../questions/native-editor/sql-parameters#field-filter-variables) variable in order to be linked. Basic SQL variables aren't connected to database columns, so they won't work for linked filters.
67
67
68
68
- You can't link filters that use "Custom List" or "From another model or question" as their value's source.
Copy file name to clipboardExpand all lines: _docs/master/data-modeling/field-types.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -173,7 +173,7 @@ When you [X-ray](../exploration-and-organization/x-rays) a table, model, or enti
173
173
174
174
### Field Filters
175
175
176
-
Knowing what field types are and how they work is helpful when using [field filters](/learn/metabase-basics/querying-and-dashboards/sql-in-metabase/field-filters), as you can only create field filters for [certain field types](../questions/native-editor/sql-parameters#field-filter-compatible-types).
176
+
Knowing what field types are and how they work is helpful when using [field filters](/learn/metabase-basics/querying-and-dashboards/sql-in-metabase/field-filters), as you can only create field filters for [certain field types](../questions/native-editor/sql-parameters#field-filters-are-only-compatible-with-certain-types).
summary: 'Text, number, and date variables let you plug basic values into your SQL code.'
11
+
---
12
+
13
+
# Basic SQL parameters
14
+
15
+
> If you want to filter on a database field in your query, you should prefer using [field filter variables](./sql-parameters), which require a different syntax.
16
+
17
+
To add a basic variable to a SQL query, enclose the variable in double braces: `{% raw %}{{variable_name}}{% endraw %}`.
18
+
19
+
This example defines a **Text** variable called `category_filter` (but you can call the variable whatever you want):
20
+
21
+
```sql
22
+
{% raw %}
23
+
SELECT
24
+
count(*)
25
+
FROM
26
+
products
27
+
WHERE
28
+
category = {{category_filter}}
29
+
{% endraw %}
30
+
```
31
+
32
+
These basic variables (that just allow basic string/number interpolation) have a different syntax than [field filters](./sql-parameters).
33
+
34
+
Here's the [field filter](./sql-parameters#field-filter-variables) syntax:
35
+
36
+
```sql
37
+
{% raw %}
38
+
WHERE
39
+
{{category}}
40
+
{% endraw %}
41
+
```
42
+
43
+
Whereas the basic variable syntax includes an `=` operator:
44
+
45
+
```sql
46
+
{% raw %}
47
+
WHERE
48
+
category = {{category}}
49
+
{% endraw %}
50
+
```
51
+
52
+
Here, we don't connect the variable to a database field; we merely insert the value into the variable.
53
+
54
+
Metabase will read the variable and attach a filter widget to the query, which people can use to change the value inserted into the `category` variable. So if someone enters "Gizmo" into the filter widget, the query Metabase would run would be:
55
+
56
+
```sql
57
+
SELECT
58
+
count(*)
59
+
FROM
60
+
products
61
+
WHERE
62
+
category ='Gizmo'
63
+
```
64
+
65
+
If you're writing a native MongoDB query, your query would look more like this, with the `category` variable being defined inside the `match` clause:
## Basic SQL variables offer limited options for filter types
72
+
73
+
-**Text**: a plain input box
74
+
-**Number**: a plain input box
75
+
-**Date**: a simple date picker
76
+
-**Boolean**: a this or that picker.
77
+
78
+
If you want a more expressive filter widget, like a dynamic date picker, you should use a [field filter variable](./sql-parameters#field-filter-variables).
0 commit comments