redash icon indicating copy to clipboard operation
redash copied to clipboard

Hey, why i can not sort by Row Lable

Open viettran97118 opened this issue 1 year ago • 2 comments

Can not sort by Row Lable. In this image sort by month_formatted can not work. It's sort by alphabet.

image

viettran97118 avatar Nov 23 '23 10:11 viettran97118

I've run into this before. Redash only supports simple sorting afaik, so what I did to sort myself was add a custom ORDER BY clause and tell redash not to sort values. In my case this was a list of 3 categories in one instance and the days of the week in another, so pretty easy to build the sort order, but maybe you'll need to order by a specific column in your case?

guidopetri avatar Nov 23 '23 12:11 guidopetri

A part of my query. I tried "ORDER BY" month_formatted. But it is not working @guidopetri.

SELECT 
    TO_CHAR(DATE_TRUNC('week',created_at)::date,'YYYY-MM-DD') AS month_formatted, 
    CASE EXTRACT(DOW FROM created_at)
        WHEN 1 THEN '1. Monday'
        WHEN 2 THEN '2. Tuesday'
        WHEN 3 THEN '3. Wednesday'
        WHEN 4 THEN '4. Thursday'
        WHEN 5 THEN '5. Friday'
        WHEN 6 THEN '6. Saturday'
        ELSE '7. Sunday'
    END AS day_of_week,
    SUM(activity) AS active_company 
FROM CTE
WHERE created_at >= '2023-01-01'
GROUP BY 1,2
ORDER BY 1 DESC

viettran97118 avatar Nov 23 '23 13:11 viettran97118