Dynamic Currency Conversion
knowledge checkpoint
A grasp of these concepts will help you understand this documentation better:
Introduction
Dynamic currency conversion allows users to view revenue and other monetary metrics in their preferred currency. Instead of creating separate metrics for each currency, you can use parameter fields to let users switch currencies on-the-fly from a dashboard filter.
Example: Multi-Currency Revenue Display
Suppose you have an international e-commerce platform and want users to view revenue in their preferred currency (MYR, USD, or THB).
Step 1: Create a Currency Parameter Model
currency_param.model.aml
Model currency_param {
type: 'query'
label: 'Currency Parameter'
data_source_name: 'your_datasource'
query: @sql select 1 ;;
param currency {
label: 'Display Currency'
type: 'text'
allowed_values: ['USD', 'MYR', 'SGD', 'THB', 'VND', 'AUD']
}
}
Step 2: Define Dynamic Metric with Currency Conversion
Add the parameter model to your dataset and create a metric that switches calculation based on the selected currency.
ecommerce.dataset.aml
Dataset ecommerce {
label: 'Ecommerce'
data_source_name: 'your_datasource'
models: [orders, currency_param]
// Base metric in original currency
metric gmv {
label: 'GMV (Original Currency)'
type: 'number'
definition: @aql sum(orders.value) ;;
}
// Dynamic metric that converts to selected currency
metric gmv_converted {
label: 'GMV (Converted)'
type: 'number'
definition: @aql case(
when: 'USD' in currency_param.currency, then: gmv * 1,
when: 'MYR' in currency_param.currency, then: gmv * 4.47,
when: 'SGD' in currency_param.currency, then: gmv * 1.35,
when: 'THB' in currency_param.currency, then: gmv * 35.5,
when: 'VND' in currency_param.currency, then: gmv * 25450,
when: 'AUD' in currency_param.currency, then: gmv * 1.57
) ;;
// the above conversion rate might be adjusted in the future
}
}
Step 3: Create Dashboard Currency Selector
- Add a dashboard filter linked to
currency_param.currency - Configure the filter as single-select (since the case statement expects one value)
- Set a default value (e.g., 'USD') to ensure the metric always has a valid calculation
Users can now switch between currencies, and the revenue metric will automatically display values in their selected currency.
See Also
- Dynamic Metric Conditions - For filtering metrics
- Parameter Fields