Dynamic Conditions in Visualization Block
A grasp of these concepts will help you understand this documentation better:
Introduction
With AQL Conditions, you can filter data in the visualization's filter section using expressions like:
buyers.buyer_gender == 'female' and sellers.seller_gender == 'female'
Dynamic Conditions take this a step further by parameterizing those values so users can control them via dashboard filters:
buyers.buyer_gender == {user_input} and sellers.seller_gender == {user_input}
This allows you to build interactive dashboards where filters apply to all metrics in the explore, without hardcoding values.
Use Case: Filter Multiple Models with the Same Condition
A common scenario is filtering data from multiple models using a single user-controlled parameter. For example, filtering both buyers and sellers by the same gender value.
Pre-requisite: This example assumes you have an ecom_transactions dataset with the following structure:
Dataset ecom_transactions {
...
models: [
buyers,
sellers,
transactions_buyers_sellers
]
relationships: [
relationship(transactions_buyers_sellers.buyer_id > buyers.buyer_id, true),
relationship(transactions_buyers_sellers.seller_id > sellers.seller_id, true)
]
}
Both buyers and sellers models have a gender dimension (e.g., buyer_gender and seller_gender).
Step 1: Create a Parameter Model
Model param_model {
type: 'query'
label: 'Param Model'
data_source_name: 'your_datasource'
query: @sql select 1 ;;
param gender_param {
label: 'Gender'
type: 'text'
}
}
Step 2: Add the Parameter Model to Your Dataset
Dataset ecom_transactions {
...
models: [buyers, sellers, transactions_buyers_sellers, param_model]
relationships: [
relationship(transactions_buyers_sellers.buyer_id > buyers.buyer_id, true),
relationship(transactions_buyers_sellers.seller_id > sellers.seller_id, true)
]
}
Step 3: Use Parameter in AQL Condition
In your visualization, add an AQL Condition that references the parameter. This filter applies to the entire explore, affecting all dimensions and metrics.
// AQL Condition in the visualization's filter section
buyers.buyer_gender == (param_model.gender_param | first())
and
sellers.seller_gender == (param_model.gender_param | first())
This single condition filters both the buyers and sellers models using the same parameter value.
Step 4: Set Up Dashboard Filter
- Create a field filter linked to
param_model.gender_param - Set its source to any gender field (from Buyers or Sellers model)
- Configure the filter as single-select (since we use
first())
Handling Single vs. Multiple Values
When using parameters in AQL Conditions:
For single-value filters, use first() to extract the first value:
buyers.buyer_gender == (param_model.gender_param | first())
For multi-value filters, use the in operator:
buyers.buyer_gender in [param_model.gender_param]
See Also
- Dynamic Metric Definition - For filtering inside metric definitions
- Dynamic Query Model - For filtering at the SQL level
- AQL Condition Reference
- Parameter Fields