Top N by Value ​
Use @aggregate to order by a computed value instead of alphabetically. This shows the top 5 occupations ranked by total income.
Interactive Example ​
Try It
TABLE ROWS occupation[-5@income.sum] COLS education * gender * income.sum ;
Dataset:
samplesoccupation, education, gender, incomeTry Variations
Query Breakdown ​
TABLE- Declares a crosstab table statementoccupation[-5@income.sum]- Top 5 occupations ordered by sum of income (descending)[-5]- Negative number means descending order (highest first), limit to 5@income.sum- Order by this aggregate value, not alphabetically
COLS education * gender- Two-level column hierarchy: education containing genderincome.sum- Measure: sum of income for each cell
Without @, limits are alphabetical. With @aggregate, they're ranked by that computed value.
Related Examples ​
- Order by Value (no limit) - Sort without limiting the count
- Alphabetic Limits - Limit alphabetically instead of by value
- Nested Limits - Apply limits at multiple hierarchy levels