Skip to main content
Defines measures that combine already-aggregated values from multiple topics in a single SQL expression. Each topic runs its own subquery first, so every ${@topic.view.field} reference is a single aggregated value by the time the shared measure sees it. Any field you reference is auto-included in the right subquery — you don’t need to also add it to the workbook.
Write the sql: as plain math over already-aggregated values — arithmetic, CASE, COALESCE, NULLIF, etc. Each referenced field is already a single aggregated value, so wrapping it in SUM(...) or COUNT(...) — or setting aggregate_type: — re-aggregates over the post-join result, which usually isn’t what you want.

Syntax

shared_measures:
  <measure_name>:
    label: <string>
    description: <string>
    format: <format>
    sql: <expression using ${@topic.view.field}>

Properties

shared_measures
object
A map of shared measure definitions, keyed by the measure’s name. The name becomes the selectable measure in the workbook.

Examples

Revenue per dollar of marketing spend
shared_measures:
  revenue_per_dollar_spent:
    label: "Revenue per $ spent"
    sql: ${@orders_topic.orders.total_revenue} / NULLIF(${@marketing_topic.campaigns.total_spend}, 0)
    format: usdcurrency_2