Skip to content

Commit 4a66a8d

Browse files
author
Metabase Docs bot
committed
[auto] adding content to docs-filters-in-headings-and-dashcards->master
1 parent a7f0518 commit 4a66a8d

File tree

284 files changed

+16548
-745
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

284 files changed

+16548
-745
lines changed

_docs/master/dashboards/filters.md

Lines changed: 70 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,15 @@ redirect_from:
1616

1717
![Dashboard Filters](./images/filters.png)
1818

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).
2020

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
2222

23-
## Adding a filter or parameter
24-
25-
![Add a Filter](./images/add-filter.png)
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.
3924

4025
### Filter widgets
4126

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

4429
- [Date picker](#date-picker-filters)
4530
- [Location](#location-filters)
@@ -50,13 +35,45 @@ The type of filter or parameter widget you choose determines how the widget work
5035

5136
### Parameter widgets
5237

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

5540
- [Time grouping](#time-grouping-parameter)
5641

42+
## Adding a filter or parameter widget
43+
44+
![Add a Filter](./images/add-filter.png)
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+
5774
## Date picker filters
5875

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:
6077

6178
- Month and Year
6279
- Quarter and Year
@@ -65,19 +82,17 @@ When picking a Time filter, Metabase will prompt you to pick a specific type of
6582
- Relative Date
6683
- All Options
6784

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

7087
## Time grouping parameter
7188

7289
![Time grouping](./images/time-grouping.png)
7390

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

7893
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.
7994

80-
You can group by:
95+
Grouping options include:
8196

8297
- Minute (or minute of hour)
8398
- Hour (or hour of day)
@@ -87,6 +102,8 @@ You can group by:
87102
- Quarter (or quarter of year)
88103
- Year
89104

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+
90107
## Location filters
91108

92109
There are four types of Location filters to choose from:
@@ -96,10 +113,21 @@ There are four types of Location filters to choose from:
96113
- ZIP or Postal Code
97114
- Country
98115

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+
99125
## ID filter
100126

101127
The ID filter provides a simple input box where you can type the ID of a user, order, etc.
102128

129+
You can give people the option to pick one value or multiple values.
130+
103131
## Number filter
104132

105133
You can choose from:
@@ -114,21 +142,25 @@ You can choose from:
114142

115143
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:
116144

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).
118146
- **Is not**. Exclude one or more specific values.
119147
- **Contains**. Match values that contain the entered text.
120148
- **Does not contain**. Filter out values that contain the entered text.
121149
- **Starts with**. Match values that begin with the entered text.
122150
- **Ends with**. Match values that end with the entered text.
123151

152+
You can also select how people should filter on this column:
153+
154+
- Dropdown list
155+
- Search box
156+
- Input box
157+
124158
## Boolean filter
125159

126160
A boolean filter allows people to filter data based on true/false values.
127161

128162
## Connecting a filter or parameter widget to dashboard cards
129163

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-
132164
For each widget that you add, you'll need to tell Metabase which column the filter should update for each card.
133165

134166
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
137169

138170
![Wiring up a dashboard filter to a card](./images/wiring-cards.png)
139171

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+
140177
## Auto-connecting filters to cards
141178

142179
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
145182

146183
## Filtering dashboards with native/SQL questions
147184

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).
149186

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).
151188

152189
## Wiring up dashboard filters to text cards
153190

@@ -201,8 +238,8 @@ A list of all of the possible values in a column. People can use checkboxes to s
201238

202239
If you're not seeing the **Dropdown list** option, and your dashboard filter is based on a column from a:
203240

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**.
206243

207244
#### Search box
208245

_docs/master/dashboards/linked-filters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Metabase uses database column metadata to populate values for linked filters, wh
6363

6464
- You can't create linked filters on custom columns.
6565

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

6868
- You can't link filters that use "Custom List" or "From another model or question" as their value's source.
6969

_docs/master/data-modeling/field-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ When you [X-ray](../exploration-and-organization/x-rays) a table, model, or enti
173173

174174
### Field Filters
175175

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).
177177

178178
### JSON unfolding
179179

-93.3 KB
Binary file not shown.
235 KB
Loading
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
version: master
3+
has_magic_breadcrumbs: true
4+
show_category_breadcrumb: true
5+
show_title_breadcrumb: true
6+
category: Questions
7+
title: 'Basic SQL parameters'
8+
source_url: 'https://github.com/metabase/metabase/blob/master/docs/questions/native-editor/basic-sql-parameters.md'
9+
layout: new-docs
10+
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:
66+
67+
```
68+
{% raw %}[{ $match: { category: {{category}} } }]{% endraw %}
69+
```
70+
71+
## 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

Comments
 (0)