Skip to main content

Metric Context

Introduction

You will encounter this term multiple times across our documents. Context encapsulates the necessary information to evaluate an expression, like the dimensions, relationships, and the filter condition that should be applied to the calculation…

For example:

context-01

This expression uses two different contexts to create a ratio metric.

Types of Metric Context

Here are the list of metric context types:

  • The condition applied to the expression, can be modified with where function
  • The relationship structure defined in the dataset where the expression is located, can be modified with with_relationships function
  • The level of detail associated with the expression, can be modified with LOD functions
  • The window function logic applied to the expression, can be modified with window functions

The context can be manipulated using a combination of metric functions. See the examples below for more clarity.

Examples

Count number of male users with where:

count(users.id) | where(users.gender == 'Male')

Sum of revenue with custom relationships:

sum(order_items.revenue) |
with_relationships(
order_items.order_id > orders.id,
order_items.country_id > countries.id
)

Total order values, regardless of dimensions, leveraging LOD functions:

sum(products.price * order_items.quantity) | exclude(order_items)

Running Total Orders by Month:

count(orders.id) | running_total(run: orders.created_at | month())

Let us know what you think about this document :)