Skip to content

Order All by Value ​

Use DESC@aggregate to order all rows by a computed value instead of alphabetically. This shows all occupations ordered by income from highest to lowest.

Interactive Example ​

Try It
TABLE
  ROWS occupation DESC@income.sum
  COLS education * income.sum
;
Dataset:samplesoccupation, education, gender, income
Try Variations

Query Breakdown ​

  • TABLE - Declares a crosstab table statement
  • ROWS occupation DESC@income.sum - All occupations ordered by income sum (descending)
    • DESC - Descending order (highest values first)
    • @income.sum - Order by this aggregate value, not alphabetically
    • No bracket limit - shows all values, just reordered
  • COLS education * income.sum - Column dimension with education breakdown
  • income.sum - Measure: sum of income for each cell

Without @, dimensions are ordered alphabetically. With DESC@aggregate or ASC@aggregate, they're ordered by that computed value. Use [-N@aggregate] to combine ordering with a limit.

Powered by Malloy and DuckDB