Skip to content

Reverse Alphabetic Limit ​

Use [-N] to show the last N values in descending order.

Definition Order for DIMENSION

For dimensions defined with DIMENSION syntax, this uses reverse definition order, not reverse alphabetical order. The values appear in the opposite order from how buckets are declared in the DIMENSION statement.

This example shows the last 5 occupations from the occupation dimension (reverse definition order: Farming, Transport, Manufacturing, Services, ...).

Interactive Example ​

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

Query Breakdown ​

  • TABLE - Declares a crosstab table statement
  • ROWS occupation[-5] - Last 5 occupations
    • [-5] - Negative number means descending order, limit to 5
    • For DIMENSION-defined dimensions, uses reverse definition order
    • For raw columns, uses reverse alphabetic order (Z-A)
  • COLS education * gender * income.sum - Three-level column hierarchy
  • income.sum - Measure: sum of income for each cell

The sign of the number controls direction: [5] gives first N, [-5] gives last N. For dimensions defined with DIMENSION syntax, ordering follows definition order by default. Add @aggregate to order by value instead.

Powered by Malloy and DuckDB