Order by Underlying Code ​
Deprecated Pattern
When using TPL-native DIMENSION syntax, definition order is automatic. You don't need to use @column.min for dimensions defined with DIMENSION - they will already sort in the order you defined the buckets.
This page documents ordering by underlying code for advanced cases or when using raw Malloy models without DIMENSION syntax.
The Modern Solution: Use DIMENSION Syntax ​
Define your dimension with DIMENSION syntax and the order is automatic:
DIMENSION education_detail FROM educ
'<HS' WHEN < 12
'HS graduate' WHEN = 12
'Some College' WHEN >= 13 AND <= 15
'College Grad' WHEN = 16
'Some Graduate' WHEN >= 17
ELSE NULL
;
TABLE ROWS education_detail * income.sum;The results will appear in definition order: <HS, HS graduate, Some College, College Grad, Some Graduate.
Legacy Pattern: @column.min ​
For dimensions defined in Malloy models (not DIMENSION syntax), alphabetic sorting gives incorrect results:
education_detail is
pick '<HS' when educ < 12
pick 'HS graduate' when educ = 12
pick 'Some College' when educ >= 13 and educ <= 15
pick 'College Grad' when educ = 16
pick 'Some Graduate' when educ >= 17
else nullAlphabetically sorted: <HS, College Grad, HS graduate, Some College, Some Graduate
Natural order (by education level): <HS, HS graduate, Some College, College Grad, Some Graduate
For these cases, use @column.min to order by the underlying code.
Interactive Example ​
TABLE ROWS education_detail ASC@educ.min COLS gender * income.sum ;
samplesoccupation, education, gender, incomeQuery Breakdown ​
TABLE- Declares a crosstab table statementROWS education_detail ASC@educ.min- Education labels ordered by underlying codeeducation_detail- The string label dimension derived fromeducASC- Ascending order (lowest code values first)@educ.min- Order by the minimumeducvalue for each group
COLS gender * income.sum- Column breakdown by genderincome.sum- Measure: sum of income for each cell
When You Still Need This ​
Use @column.min ordering when:
- Using raw Malloy models - dimensions defined in Malloy (not TPL
DIMENSIONsyntax) don't have definition order metadata - Ordering by a different column - e.g., sorting product names by product_id
- Complex ordering logic - when definition order isn't the natural order
For new development, prefer DIMENSION syntax for automatic definition-order sorting.
Related Examples ​
- Order by Value - Order by aggregated values
- Order by Different Aggregate - Sort by one measure, display another
- Alphabetic Limit - Default alphabetic ordering