dimensionalize (previously exact_grains)
We have renamed exact_grains
to dimensionalize
to align with how the function is used in practice.
While we will continue to support exact_grains
for backward compatibility, please use dimensionalize
to ensure that your code is readable.
Definition
Evaluate an expression using a specific Level of Detail (LoD) context, regardless of the outer context. You can use dimensionalize
for use cases like dimensionalized measure and cohort analysis.
This is only allowed in the definition of a Dimension, and not elsewhere.
Syntax
dimensionalize(measure, dimension, ...)
dimension order_value {
description: "Total order value of this user"
definition: @aql dimensionalize(sum(order_items.order_value), users.id) ;;
}
// with pipe
dimension order_value {
description: "Total order value of this user"
definition: @aql sum(order_items.order_value) | dimensionalize(users.id) ;;
}
Input
measure
: A measure that you want to evaluate against a specific LoD context.dimension
(repeatable): A dimension that you want to use as the LoD context.
Output
A new dimension
Sample Usages
The following example creates a dimension customer_lifetime_value
, by dimensonalizing the measure total sales
dimension customer_lifetime_value {
...
definition: @aql sum(orders.amount) | dimensionalize(users.id) ;;
}
Total orders amount of this user equal to customer lifetime value field
We can also reuse this dimension just like other dimension to derive further analytics insight. Let's define average_customer_lifetime_value
metric
metric average_customer_value {
...
definition: @aql average(users.customer_lifetime_value) ;;
}
Using the above metric to find Average Customer Lifetime Value per Continent