Overriding Parent Filters
In your workspace, you can specify data filters at the metric, visualization, and dashboard levels. These filters change the computed values displayed in your visualizations.
Filters are applied to the data based on an order of precedence, in which dashboard filters are given the highest priority, followed by visualization filters and then filters within metric definitions.
In your metric definitions, you can specify overrides of the filters that have been specified in higher-level (parent) objects in your workspace.
A parent filter is any data filter applied to a workspace object from one of its parent objects. A parent object can be considered any visualization that contains the metric or another metric built on the metric.
- For example, if your visualization filter is defined to be Channel = Twitter, then by default all metrics in the visualization are computed for data that matches Channel = Twitter. Similarly, if the dashboard filter is set to Date = June 2, 2014, then all metrics in the visualization calculated from data matching Date = June 2, 2014 and Channel = Twitter. However, other visualizations on the dashboard are only filtered by the date value.
- If there is a dashboard filter and a visualization filter on two different attributes: data must match both filter conditions in order to appear in the visualization. In the MAQL query for the visualization, a logical AND is applied between the filters.
- If the dashboard filter and visualization filter are on the same attribute: the dashboard filter overrides the visualization filter.
Only positive filters are overridden. Any negative filters added (for example ISN’T) are not overwritten.
A metric’s parent filters can be specified in any visualization or dashboard containing the metric or in any metric in which the original metric is nested.
These filters are applied to a metric’s data before the computations has been executed.
In some cases, however, you may want to override parent filters or to specify which of these filters to apply from within your metric definitions. These visualization filter overrides can be an important method for maintaining control over the data that is displayed for a metric.
For example, suppose your Total_Employees metric should display a single, consistent value wherever it is used in the workspace. However, your data model may make it possible to filter this metric by attributes such as Region or Office_Location in metrics, visualization filters, and dashboard filters. By adding the WITHOUT PARENT FILTER keyword to the metric definition, you ensure that the Total_Employees metric returns a consistent value no matter where and how it is used in the workspace.
Applying visualization filter overrides to your metric definitions can be very important to ensure consistency in usage. However, you should avoid overusing these overrides, as they can make your metrics less flexible and create debugging issues.
PARENT Keywords
MAQL supports a set of keywords that can be used to override and control which parent-level filters are applied to a specified metric. When inserted into your metric definition, these keywords specify whether to apply any filters from the metric’s parent metric, visualization, or dashboard to the data used in the metric calculation.
You can include or exclude all filters or specify the specific filters to include or exclude.
These keywords are applied to selecting data before it has been aggregated in the metric computation. For more information on applying filtering to data after it has been aggregated, see Filtering with the HAVING Clause
The effects of these keywords are best demonstrated by example. Suppose you have the following metric (M1), which has visualization-level filters applied to it:
Definition | visualization Filter | Metric Value |
---|---|---|
SELECT M1 | (none) | 500 |
SELECT M1 | F1: Group = X | 350 |
In the above table, you can see the value generated for the metric (M1) is 500 when no filtration is applied. When the visualization filter (F1) is applied, the value for the metric is 350. This example can be used to describe the effects of each of the following parent keywords.
If your metric contains multiple keywords, they must be listed in alphabetical order:
SELECT (...) (BY ...) (FOR ...) (WHERE ...|HAVING ...) (WITH PF|WITH PF EXCEPT|WITHOUT PF|WITHOUT PF EXCEPT)
For any metric that utilizes the WITH or WITHOUT keywords to override visualization filters, you should include an indicator in the metric name. For example, you might append [WO/PF] to any metric's name that uses the WITHOUT PF keywords.