Repository navigation
How can i sort y axis with category name #42790
Replies: 2 comments 2 replies
|
@PARKER-X The trick is to keep your text labels as the dimension and use the numeric CASE expression as a separate sorting metric — not as the dimension itself. Here's how:
This way the chart displays the text labels but orders them by the hidden numeric value. Simpler alternative: If the above doesn't work well for your chart type, you can prefix the labels with zero-padded numbers in your CASE expression [1]: CASE
WHEN experience_band_sort = 1 THEN '01. 0-5 yrs'
WHEN experience_band_sort = 2 THEN '02. 5-10 yrs'
WHEN experience_band_sort = 3 THEN '03. 10-15 yrs'
WHEN experience_band_sort = 4 THEN '04. 15-20 yrs'
WHEN experience_band_sort = 5 THEN '05. 20+ yrs'
ENDAlphabetical sorting will then naturally produce the correct order. Note: Superset doesn't have a built-in UI for arbitrary custom category ordering, so a data-driven approach like one of these is the standard way to handle it [2]. To reply, just mention @dosu. Share context across your team and agents. Try Dosu. |
|
When working with categorical bands (such as You can sort your categories in the correct logical sequence without displaying numeric prefixes ( Method 1: Use a Custom SQL Metric in the "Sort By" Control (Recommended)In the chart configuration panel in Explore:
MIN(CASE experience_band
WHEN '0-5 yrs' THEN 1
WHEN '5-10 yrs' THEN 2
WHEN '10-15 yrs' THEN 3
WHEN '15-20 yrs' THEN 4
WHEN '20+ yrs' THEN 5
ELSE 99
END)
Because this SQL expression is added to the generated Method 2: Dataset Calculated Column with Zero-Width Unicode SpacesIf your chart plugin does not expose a separate Sort By metric when grouping categories:
CASE
WHEN experience_band = '0-5 yrs' THEN CONCAT(CHAR(8203), '0-5 yrs')
WHEN experience_band = '5-10 yrs' THEN CONCAT(CHAR(8203), CHAR(8203), '5-10 yrs')
WHEN experience_band = '10-15 yrs' THEN CONCAT(CHAR(8203), CHAR(8203), CHAR(8203), '10-15 yrs')
WHEN experience_band = '20+ yrs' THEN CONCAT(CHAR(8203), CHAR(8203), CHAR(8203), CHAR(8203), '20+ yrs')
ELSE experience_band
ENDAlphabetical sorting will naturally sort by the invisible character count while human eyes in the browser see clean text labels. |
Uh oh!
There was an error while loading. Please reload this page.
how can i sort 0-5,5-10 etc

I tried CASE experience_band_sort
WHEN 1 THEN '0-5 yrs'
WHEN 2 THEN '5-10 yrs'
WHEN 3 THEN '10-15 yrs'
WHEN 4 THEN '15-20 yrs'
WHEN 5 THEN '20+ yrs'
ELSE 'Unknown'
END
if i use experience_band_sort than it works but don't want 1,2,3,4,5 etc i hope u understand what am i trying to say
All reactions