Skip to main content

exact_grains

info

This is part of our beta expression language AQL. Learn more. Request beta.

Definition

Evaluate an expression using a specific Level of Detail (LoD) context, regardless of the outer context. You can use exact_grains for use cases like dimensionalized measure and cohort analysis.

caution

This is only allowed in the definition of a Dimension, and not elsewhere.

Syntax

exact_grains(measure, dimension, ...)
Examples
dimension order_value {
description: "Total order value of this user"
definition: @aql exact_grains(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) | exact_grains(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.

Returns

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) | exact_grains(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


Let us know what you think about this document :)