Trouble with order by in stacked bar chart

Hi there!
I have the following query:

SELECT 
    query_1.info1 AS info1 
    query_1.info2 AS info2, 
    query_1.info3 AS info3,
    query_2.info1/query_2.info2 AS div
FROM 
    (query 1) AS query_1 
INNER JOIN  
     (query 2) AS query_2
on query_1.key= query_2.key
ORDER BY div DESC

That produces a stacked bar chart. I want the columns be ordered by div but I am getting this undesireble result:

leg

The columns is folowing what I want (order by div) but the numbers is not ok.
I already try this (without success):

SELECT *
FROM
(SELECT 
    query_1.info1 AS info1 
    query_1.info2 AS info2, 
    query_1.info3 AS info3,
    query_2.info1/query_2.info2 AS div
FROM 
    (query 1) AS query_1 
INNER JOIN  
     (query 2) AS query_2
on query_1.key= query_2.key
ORDER BY div DESC)     ORDER BY info2 

info2 is what give me the numbers on the graph.

Hi @Helena
So is div returning strings or numeric values?
It's difficult to say what's going on without looking at the raw data returned. We don't have your data, so you'll need to show some example returns. Can you try reproducing with Sample Dataset?

Hi @flamber
div is returning numeric values (I used div::REAL to convert from string to numeric)

My final table is just like that:

ex

and the configuration of the stacked bar chart:

graph

is it better to understand?

@Helena Then you should order by answer, since that's your breakout (what is shown in the legend).

@flamber I thought about it, but I want the columns be ordered by div. Can't I have this type of ordering? by div and my numeric legend also ordered?

@Helena I don't understand. Please try to create something with Sample Dataset. It works fine on 0.39.1, when I test. I can see that you're not using the latest release.
Perhaps you're looking for this:
https://github.com/metabase/metabase/issues/7625 - upvote by clicking :+1: on the first post

@flamber
I made this exemple on Sample Dataset:

SELECT 
  PRODUCT_ID, 
  REVIEWER, 
  RATING, 
  ID 
FROM REVIEWS
WHERE CREATED_AT BETWEEN '2020-01-01 00:00:00' AND '2020-01-31 23:59:59' 
ORDER BY ID

query results:

conf

I want the columns be ordered by ID but I also want that my legend (rating) be ordered correctly.

If I change to:

SELECT PRODUCT_ID, REVIEWER, RATING, ID FROM REVIEWS
WHERE CREATED_AT BETWEEN '2018-04-01 00:00:00' AND '2018-07-31 23:59:59' 
ORDER BY ID

results:

@Helena Okay, that's not possible until the issue is implemented.

Thanks!