superset icon indicating copy to clipboard operation
superset copied to clipboard

[Question] How to filter date data with bar chart.

Open mingyumkim93 opened this issue 6 years ago • 7 comments

Hello everybody, thank you for reading this.

To explain what I want to get, let's say there is table that has 3 columns: name, starting date, ending date. I want to show how many days are in between starting date to ending date with bar graph grouped by name so that X axis shows names and Y axis shows the number of days. For instance one row has name "A", starting date 2019-10-15, ending date 2019-10-30 so one bar will show name A has 15 days. This was easy when I do without time filter but problem I found is that when I want to show how many days are in certain time frame that user set. For instance, when user wants to see only for 2019-10-20 to 2019-12-01 from same data above, it should show only 10 instead of 15. I hope my question makes sense.

Does anybody have good idea how to solve this?

mingyumkim93 avatar Dec 15 '19 14:12 mingyumkim93

Issue-Label Bot is automatically applying the label #question to this issue, with a confidence of 0.84. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

issue-label-bot[bot] avatar Dec 15 '19 14:12 issue-label-bot[bot]

In custom sql on metrics field, you can use "<date column 1> - <date column 2>". This should help in your scenario.

hemantaggarwal avatar Dec 16 '19 09:12 hemantaggarwal

@hemantaggarwal Thank you very much for your reply but I still couldn't get what I want. For instance I have "starting_date","ending_date" (not actually since it's in different language), I tried <ending_date>-<staring_date> and it gives "incorrect syntax" error. Could you give little more example?

mingyumkim93 avatar Dec 16 '19 10:12 mingyumkim93

@mingyumkim93 Your query syntax should be according the sql database you are using. For example I am using postgres as source in superset, so I have to use "ending_date" - "starting_date" in custom sql in metric field, also columns should be of date type. Below is one screenshot.

image

hemantaggarwal avatar Dec 16 '19 11:12 hemantaggarwal

@hemantaggarwal Thank you very much, now I got it better hot it works. So it seems that I can't do what I want by setting time column and time range but maybe I have to do this in custom SQL somehow. Thank a lot for your help!

mingyumkim93 avatar Dec 16 '19 12:12 mingyumkim93

Yes, use custom sql to find difference between dates and if you also want dynamic time range then in time range filter choose either start_date or end_date as time column.

hemantaggarwal avatar Dec 16 '19 16:12 hemantaggarwal

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For admin, please label this issue .pinned to prevent stale bot from closing the issue.

stale[bot] avatar Feb 14 '20 16:02 stale[bot]