Measures (or metrics) are aggregations performed inside a SQL group by statement. A simple one is sum(sales), which you could specify in your data model with type: sum and sql: ${TABLE}.sales. Measures can become highly complex, offering flexibility that leverages the full power of your SQL syntax.


Properties of a Measure (or Metric)


Examples

Simple Example: This example defines a few dimensions and measures for the order_lines view, showing how the SQL statements and different properties are applied.

version: 1
type: view
name: order_lines
model_name: demo_model
sql_table_name: prod.order_lines

fields:
- name: order_line_id
  field_type: dimension
  type: string
  sql: ${TABLE}.order_line_id
  primary_key: yes

- name: price
  field_type: dimension
  type: number
  sql: ${TABLE}.item_price

- name: avg_price
  field_type: measure
  type: average
  sql: ${price}

- name: total_price_order_level
  field_type: measure
  type: sum_distinct
  sql_distinct_key: ${order_id}
  sql: ${price}

- name: number_of_orders
  field_type: measure
  type: count_distinct
  sql: ${order_id}

- name: cumulative_orders
  field_type: measure
  type: cumulative
  measure: number_of_orders
  description: "The unique cumulative number of orders"

Summary

In Fluent, measures (or metrics) represent aggregated calculations based on the data in your database. They are defined using properties such as name, field_type, type, and sql. You can also apply filters to measures, set cumulative calculations, and even configure non-additive dimensions for cases where simple aggregation is not applicable (e.g., MRR or inventory). Additional properties such as value_meanings, use_when, and dont_confuse_with help improve the usability of your model, guiding both the LLM and end users in how to best apply these metrics.

Through examples, we see how various types of measures, such as averages, distinct counts, and cumulative measures, can be constructed with appropriate SQL expressions and aggregation types. The rich set of properties ensures that your model remains both flexible and powerful.