Skip to content

Measure Binding ​

Bind multiple measures to multiple aggregations with (measures).(aggregations) syntax.

Interactive Example ​

Try It
TABLE
  ROWS occupation * gender
  COLS education * (income | hourly).(sum | mean)
;
Dataset:samplesoccupation, education, gender, income
Try Variations

Query Breakdown ​

  • (income | hourly) - Two measures concatenated: income and hourly wage
  • .(sum | mean) - Two aggregations applied to each measure
  • Result: 4 aggregate columns per education level (income.sum, income.mean, hourly.sum, hourly.mean)
  • occupation * gender - Two-level row hierarchy

The measure binding syntax (measures).(aggregations) creates a cartesian product: each measure gets each aggregation. This is more concise than writing income.sum | income.mean | hourly.sum | hourly.mean.

Per-Aggregation Formats ​

You can apply different formats to each aggregation using the aggregation:format syntax:

tpl
income.(sum:currency | mean:decimal.2)

This applies currency format to the sum and 2-decimal format to the mean. Each format applies only to its aggregation.

Powered by Malloy and DuckDB