Skip to content

Multiple Aggregates ​

Use | to show multiple aggregates as sibling columns. The parentheses group the aggregates together.

Interactive Example ​

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

Query Breakdown ​

  • TABLE - Declares a crosstab table statement
  • ROWS occupation - Row dimension: occupation values become row headers
  • COLS education - Column dimension: education levels become outer column headers
  • (income.sum | income.mean) - Multiple measures: sum and mean appear as sibling columns under each education level

The | operator concatenates measures horizontally, creating separate columns for each aggregate function applied to the same field.

Available Aggregations ​

TPL supports these aggregation methods:

MethodDescription
sumSum of values
mean / avgAverage
count / nRow count
minMinimum value
maxMaximum value
stdevStandard deviation
median / p50Median (50th percentile)
p25First quartile (25th percentile)
p75Third quartile (75th percentile)
p90, p95, p99Higher percentiles

Use them with the dot syntax: field.sum, field.mean, field.p50, etc.

Powered by Malloy and DuckDB