Skip to content

Nested Limits ​

Apply limits at multiple nesting levels in a hierarchy. This shows the top 3 occupations by income, then the top 2 education levels within each.

Interactive Example ​

Try It
TABLE
  ROWS occupation[-3@income.sum] * education[-2@income.sum]
  COLS gender * income.sum
;
Dataset:samplesoccupation, education, gender, income
Try Variations

Query Breakdown ​

  • TABLE - Declares a crosstab table statement
  • ROWS occupation[-3@income.sum] * education[-2@income.sum] - Nested hierarchy with limits at each level
    • occupation[-3@income.sum] - Top 3 occupations by income sum
      • [-3] - Negative means descending order, limit to 3
      • @income.sum - Order by this aggregate, not alphabetically
    • education[-2@income.sum] - Within each occupation, top 2 education levels by income
  • COLS gender * income.sum - Column dimension with gender breakdown
  • income.sum - Measure: sum of income for each cell

Each level of the hierarchy can have its own independent limit and ordering. The inner limits are applied within the context of each outer group.

Powered by Malloy and DuckDB