Measure properties
Measures are the business metrics that calculate a value for a model. Here are a few examples of measures:
total_rowscompiles tocount(*),unique_userscompilescount(distinct user_id)in SQL.
Measure Fields
dimension: | column: | sql:
dimension: | column: | sql:One of dimension, column, and sql should be set in order to define the measures under model.meta.rakam.measures. If it's not set, the measure simply counts the all rows (i.e. count(*)). Here are a few examples:
models:
- name: events
meta:
rakam:
measures:
total_rows:
aggregation: count
unique_users:
aggregation: count_unique
dimension: user_id
unique_users_total_rows_ratio:
sql: {{measure.total_rows}}/{{measure.unique_users}}
Please note that these fields are not required under column.meta as they point to the relevant column.
column: references the column in the model target.
dimension: references the dimensions within the same model.
sql: lets you define complex expression, where column type measure is not capable of.
For referencing other entities inside a measure checkout the SQL Context.
aggregation:
aggregation:The aggregation function that will be applied to to the measure value dimension | column | sql.
Here are the valid values:
count, count_unique, sum, minimum, maximum, average, approximate_unique
total_users:
dimension: 'user_id'
aggregation: approximate_unique
aggregation is not required if the sql is defined. Here is an example:
total_events_user_ratio:
sql: {{measure.total_rows}} / {{measure.total_users}}
filters:
filters:You can restrict a measure to aggregate only certain dimension values, without applying a filter to an entire query. Here is an example:
event_last_week:
aggregation: count
filters: [{dimension: occurred_at, value: 1 week, operator: between}]
The measure above compiles to the following SQL expression:
COUNT(CASE WHEN WEEK(now(), occurred_at) < 1 THEN NULL ELSE 1)
Updated over 4 years ago
