eugeniamz commented on issue #9518: Help needed - Days interval grouping in 
distributed bar chart
URL: 
https://github.com/apache/incubator-superset/issues/9518#issuecomment-612943099
 
 
   In the customize tab you have an option to sort based on the series.
    
   
![image](https://user-images.githubusercontent.com/58375897/79131480-aec54c00-7d76-11ea-82d0-ed178eaea2df.png)
   However you have to have the intervals sorted. In my example you can see 
that I add 1-<30 days, 2-30-60 days, etc. 
   
   I am not sure how you did the interval section. In my example : 
   1- I took your data and loaded in a table 
   ```sql
   CREATE TABLE sales_test (
        customer VARCHAR(10)
        ,ammount NUMERIC(9, 2)
        ,sales_date DATETIME
   );
   ```
   
   2- I created a view at the top of the table to calculate the interval with 
Sysdate() so it is updated 
   ```sql 
   CREATE VIEW sales_test_interval AS
   SELECT *
        ,datediff('day', sales_date, sysdate()) AS sales_interval
   FROM sales_test;
   ```
   3- I use Calculated fields in superset to put the interval in 'buckets' 
   
   
   
![image](https://user-images.githubusercontent.com/58375897/79131888-56427e80-7d77-11ea-9494-328120798f5d.png)
   
   It is just a case statement that most query engine accept
   ```sql
   CASE 
                WHEN sales_interval <= 30
                        THEN '1- < 30 Days'
                WHEN sales_interval BETWEEN 31
                                AND 60
                        THEN '2- 30-60 days'
                WHEN sales_interval BETWEEN 61
                                AND 180
                        THEN '3- 60-180 days'
                WHEN sales_interval > 180
                        THEN '4-More 180 Days'
   END 
   ```
   HTH. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to