Lynk docs
  • Introduction
  • Reference
    • Data Modeling
      • Entities
      • Relationships
        • Entity-to-Entity Relations
        • Entity-to-Asset Relations
      • Features
        • Field
        • Metric
        • First-Last
        • Formula
        • Filters
        • Chaining Features
      • Measures
      • Data Assets
      • Time Aggregations
      • Lynk Functions
        • POP
      • Context
    • Consume & APIs
      • Authentication
      • SQL API
      • SQL REST API
      • Cache & Pre-Aggregations
    • Governance
    • Integrations
      • Git
      • Query Engines
    • AI Agents
Powered by GitBook
LogoLogo

Start now

  • Request Access

Website

  • Home
On this page
  • Defining Measures
  • Name
  • Description [optional]
  • SQL
  1. Reference
  2. Data Modeling

Measures

PreviousChaining FeaturesNextData Assets

Last updated 3 days ago

Measures are reusable and governed components that define how an entity or a data asset should be aggregated.

Lynk applies the measure logic in two scenarios:

  1. Once a feature of type is created or consumed

  2. Once aggregating (rolling-up) an entity by some of it's features and using the MEASURE() function

Defining Measures

Measures are definitions of how aggregate functions should be applied to features and fields

# db_prod.core.orders.yml

measures:
- name: total_order_amount
  description: sum of order amount
  sql: sum({total_amount})

Name

Give the measure a name. This will be used when creating features and also will be shown on the Studio UI. It is recommended to give measures informative names that indicate their purpose.

Description [optional]

Describe the measure. It is recommended to give measures informative names that indicate their purpose - for other team members to be able to reuse the measure and for AI apps as well.

SQL

The measure definition. It should be composed of an aggregate function and a field. It is possible to chain multiple aggregate functions and / or multiple fields, just like you would do on plain SQL when needed.

Lynk is SQL-first, meaning anything that would work on plain SQL will work with Lynk as well. You can type any SQL aggregate function compatible with your query engine, and Lynk will apply that as the measure definition and chain it to the query engine.

Examples: SUM , COUNT , MIN , MAX , COUNT DISTINCT , APPROX_PERCENTILE etc

Some more examples:

# db_prod.core.orders.yml

measures:

- name: count_orders
  description: count of orders
  sql: count(1)

- name: total_order_amount
  description: sum of order amount
  sql: sum({total_amount})

- name: successful_order_amount
  description: sum of successful orders amount
  sql: sum(IFF({order_status} = 'success', {total_amount}, 0))
metric
metric