Skip to content

Filtering data

There are several ways to filter data rendered in a dashboard:

  • Static filter in a widget: this lets you define a filter in a single widget. The viewer can't modify the filter. You can define several static filters in a widget.
  • Dynamic filter in a widget: this lets you define an editable filter in a widget. The viewer will be able to use it to filter the data displayed in the widget. You can add several dynamic filters per widget.
  • Dynamic filter widget: this is a particular widget used to encapsulate dynamic filters applied to a full tab. A viewer can use this filter widget to filter the data of a given tab.
  • Global static filter: used to define a filter on a datasource in a dashboard. This filter will be applied to all widgets using this datasource in all the tabs of the dashboard. The value used in a global static filter can be defined in the dashboard. But it can also be passed dynamically to the dashboard. In this second case, the dashboard is called a template dashboard. See here for the documentation about this option.

Static filter in a widget

In the Filter section of a widget configuration, to define a filter, you need to select the dimension, operator and value.

Using date/time filters

For date/time dimension, you can use special filters: the same as in data sources formulas.

Using In/Not in filters

When using the In operator, you must provide a list of string or integer values.

Examples:

  • filtering specific ids:
[42, 567, 4095]
  • filtering specific quarters:
["Q1", "Q3"]

When you are using a dashboard template, you can use the special value "$$all$$" in In filters payloads to provide an admin dashboard with all the data.

Dynamic filter in a widget

In the Filter section of a widget, you just need to select the dimension you want to filter on. It will automatically add a selector at the top of the widget to let you or a viewer filter the widget. You can add as many filtering dimensions as you need per widget.

Dynamic filter widget

To add a filter bar, click on the Filter Widget icon in the list of widget types. This adds a new empty widget. In the widget configuration, click on the '+' to add a new filter. This adds a new item in the filter list below.

Click on the item added in the list, and select the source and the dimension you want to filter on. If you want this filter to be applied to other datasources, click on the button "+ source and measure". This is useful for example when you want to filter per country and you want to filter with the selected value in several datasources.

Using dynamic filters to define a variable

By default, when a dynamic filter is used, the widget(s) will be modified according to the value of the filter.

If you activate the Store selected value as variable option, the selected value of the filter will only be stored in a variable but no filtering will be applied to the widget(s). Here, the user's choice is stored in a variable named myCity :

var_dynamic_filter

Use a naming convention for your variables

When using variables, it's a good practice to use a naming convention. Here we used the prefix "my". You can use the prefix "var" (e.g. varCity). Another one is to use two underscores as prefix and postfix (e.g. __city__). The convention in itself is not important. What is important is to stick to it globally (in your filters, your widgets, your snippets...). It makes you dashboard easier to be understand by someone else ( or by you in a few months).

To apply the value to the widget(s), you need to use the defined variable within static filters. This lets you use a formula to modify the filtered value before passing it to the static filtering.

Example:

Let's say you have a column month with the format YYYY-MM (e.g. 2017-07) and you create a dynamic filter widget using this column, with the option Store selected value as variable enabled (using myMonth as the variable name).

To show data of the selected month within a first widget, you can create a static filter on column month with operator == and with value {{myMonth}}.

To show data of the month before the selected month within a second widget, you can create a static filter on column month with operator == and with value {{dateAdd(myMonth, -1, "month", "YYYY-MM")}}.

Specify the list of widgets IDs to filter

By default, a dynamic filter will be applied to all widgets in its tab. If you need, you can specify to apply a given filter only to a set of widgets.

To do that, enter the list of ID in the field IDs of widgets to filter. You must provide it as a comma separated list, e.g. 3,10,7 to filter widgets 3, 10 and 7.

To retrieve the ID of a widget, open the design tab and then open the Advanced Styles Editor. The ID of the selected widget will be displayed.

Global static filter

In the global options of the dashboard (last configuration tab), global static filters can be created in the Global filters section. You need to select each datasource you want to filter in the dashboard, the dimension you want to filter and the value. Once a filter is created here, all widgets in all tabs of the dashboard will be filtered.

In the list of datasources, the icon ✓ means the datasource has a global static filter applied. This helps you to quickly find datasources having a filter. Note that only the datasources being used in the dashboards appear in this list.

Using variables in global static filters

Instead of entering a value in a global static filter, you can use a variable. For example, you can type {{__year__}} in the value field of the filter:

Global filter example with template

The error says that the variable must be defined. There are two ways to fill this variable named __year__ :

  • in the Dashboard variables, you can enter a JSON containing the values:

Dashboard variables

This is particularly useful when you need to create a new dashboard for a different year. You can clone the existing dashboard and then you only have to replace the variable with the new year in the newly created dashboard.

  • or you can dynamically pass a payload to the dashboard (i.e. pass the variables only when the dashboard is opened by a viewer). In this second case, the dashboard is called a template dashboard. See here for the documentation about this option.

Dashboard variables are available in the datasource formulas!

The variables defined in a dashboard are passed to the datasource formulas so you can use these variables in a formula. See here for more details.

Dynamically set filters' values using the query string

This is an advanced topic

This feature is mostly used by dashboards in embedded mode.

When you open a dashboard, the dynamic filters have the default values you defined in the filters' settings. But in some cases, you have created a single dashboard and you want this dashboard to have different default values. For example, you created a dashboard with sales for different business units. You want the dashboard to open with the default value of the business unit of the user. But you want him to be able to select any other business unit in a dynamic filter.

Do achieve that, you can create a classic dynamic filter and pass the values to select in this filter dynamically in the query string of the dashboard.

For example, if the dashboard URL in the viewer is: http://app.serenytics.com/viewer/webapps/0711c198-8164-4fc5-9790-8756ffd4b3a0

you will have to use the URL: http://localhost:8000/viewer/webapps/0711c198-8164-4fc5-9790-8756ffd4b3a0?dynfilters=PAYLOAD

where PAYLOAD defines the filters' values to use.

Compute the payload

The payload to pass here is a base64 encoded JSON. This JSON must have the syntax: {WIDGET_ID: {DYNFILTER_UUID: VALUES}}

where:

  • WIDGET_ID is the widget Id of the filter widget. It is shown when you click in the top-right popup menu on the widget in the studio editor. Keep in mind that a filter widget can encapsulate several filters.
  • DYNFILTER_UUID is the technical id of the filter. This is required as a filter widget can encapsulate several filters. This unique identifier can be found in the filter's setting (the right pane that opens itself when you click on the cog beside the filter name).
  • VALUES: the list of values to select in the filter.

For example, here is a valid JSON: {"2": {"cc3f615dd90639f1":["France","Belgium"]}}

This JSON says that for the widget 2, the filter cc3f615dd90639f1 must have the values "France" and "Belgium" selected.

In the URL, this JSON must be encoded in base64. There are many libraries to achieve this encoding. For test purpose, you can use an online tool such as https://www.base64encode.org/. Before encoding your JSON, it's a good idea to check that it is a valid JSON with a tool such as https://jsonlint.com/.

For example, the above JSON encoded in base64 is: eyIyIjogeyJjYzNmNjE1ZGQ5MDYzOWYxIjpbIkZyYW5jZSIsIkJlbGdpdW0iXX19.

Of course, you can build more complex JSON with several widgets and/or several filters.