Sometimes you want to analyze only a subset of your data. To achieve this you can use filters. In the GoodData platform, you can apply filters at any of the three stages of your analysis:
- when you modify your measures (also called metrics)
- when you build insights
- when you display KPI dashboards
Measure level filters limit what data enters that specific calculation, insight level filters limit what data is available to all measures and attributes in that insight, KPI dashboard level filters limit what data is available to all insights on that dashboard. Only certain user roles can create and edit measure and insight level filters but all roles can change KPI dashboard level filter selections.
This gives you a wide array of options to filter data for your specific use cases.
Filter your measures
When you create or modify measures using filters, you define how your data are used for the analysis. By applying filters at this stage, you exclude specific range of data from being used for computation.
Note: To create or modify a measure you need to have at least editor level access to a workspace. See User Roles.
Let’s say that you want to add a filter to the # of Orders measure as you only want to see delivered orders.
- When in your workspace, click Manage, the click Metrics (another word for measures) and either create a new metric or edit an existing one.
- To start editing the measure click its name and, when the following screen appears, click Edit.
MAQL metrics editor opens. This is where you change the definition of the measure.
- Edit the definition and add a filtering condition to it. These conditions always start with WHERE keyword (see Filtering with the WHERE Clause).
- When you are happy with the new definition, save it and start using it in your insights.
Note: If you are already using this measure in some insights these will get automatically updated with the new definition.
Using Filters on insights
Another level you can apply your filter on is your Analytical Designer insights. By applying filters on insights, you exclude specific range of data from being used for analysis.
Note: To build/edit insights you have to have at least Explorer role. See User Roles.
Let’s say that you want to see # of Orders by the Product Category but you only want to count orders that were delivered.
You have two options here:
- you can use the modified measure from the previous section
- you can use an insight level filer
To use an insight level filter:
- Drag and drop the attribute from the list of attributes to the filter section:
Select the value that you want in the filter.
The chart will recompute itself.
When you save the insight, the filter and the selected value will be saved along with it.
For more details, see Filters in Analytical Designer.
Using Filters on KPI Dashboards
Another option you have is to use KPI Dashboard filters. By applying filters on KPI Dashboards, you hide specific range of data from being displayed on the dashboard.
Note: The important, and the most intriguing thing, on KPI dashboards' filter is that they can be applied by anyone who views the dashboard.
There are currently two kinds of filters available for KPI Dashboards:
- attribute filter
- date filter - to learn more, see Date Filters in KPI Dashboards
Using KPI dashboard filters
To filter only on Delivered orders, use an attribute filter instead of the measure or insight level filter.
To do that:
- Switch to edit mode on a dashboard.
- Drag and drop the Attribute Filter component next to the default Date range filter component.
- Select the Order Status attribute from the drop-down menu of the Attribute Filter component.
- Once you select the attribute, you can select which values should be selected by default when a user comes to the dashboard.
Advantages of KPI dashboard filters
The important thing to realize is that all users - even viewers - can change KPI dashboard filter values.
This means that the user will be able to change the selection from for example Delivered to Returned or select all.
Note: This change of selection doesn’t modify the default values set, it only applies within that user’s session and will reset next time the user visits the dashboard. In some cases this is what you want but in some cases you don’t want viewers to be able to change the selection - in that case use a measure or insight level filters instead.
Another feature of all filters on the KPI dashboards is that you can select which insights the filters should apply to. By default, all filters apply to all insights you placed on the dashboard. If you want to prevent a specific filter from applying to a specific insight simply click on the insight and uncheck the filter you want it to ignore.
In the example above, we unchecked the date.
When to use which type of filter
There are always exceptions but the best practices are:
- Use a measure level filter if you plan to use the same filtered metric in several insights.
That way you only have to define the filter once instead of defining it over and over again for each single insight. Apart from easier maintenance it also standardizes the definition of the metric for everybody.
- If you have a very specific scenario that won’t repeat or if you are just quickly prototyping, insight level filters might be what you are looking for.
- If you are putting your insights on a KPI dashboard and want to enable the consumers of the dashboard to dynamically change the filter value, use the KPI dashboard level filter.
How do all these filters interact?
Now you might be asking what happens if you set filters on multiple levels.
All filters that apply to an insight - no matter what level they are defined on - will be connected by the AND operator. That means that a combination of the filters will apply and only rows of data that satisfy all the different filtering conditions will enter the calculation.
If, for example, the measure is filtered on Order Status = Delivered and the KPI dashboard filters on Order Status = Canceled the insight won’t return any data as each order is associated with a single Order Status value in our case.
You might get into a situation where you add a filter but it doesn’t change the numbers. This typically means that you are trying to filter on something that is not connected to the data points that you are using in your measures/insights in the LDM (logical data model). To learn more about the LDM Modeler and data modeling on the GoodData platform, see Data Modeling in GoodData.