Can't seem to sort the dates on the X-axis
Hello, I have 2 cards next to each other. One has a date field in the dataset already and another one date is calculated like this DATE(STR_TO_DATE(LEFT(Date + hour
, 8),'%Y%m%d')) where the field "Date + Hour" field looks like this
Even though the calculated field shows as type "Date" the chart sorts it as if it was a string, see the chart on the right.
Anyone has an idea on how to fix it?
Thanks
Alek
Best Answers
-
It appears to be sorting…just not the sort you are looking for. When I do values using year & month, I create a monthname and a month (integer value). For example monthname(CURRDATE()) might give me "April". Whereas month(CURRDATE()) would give me "4". I put the monthname version on the card and put the month version on the sort. That way monthnames are sorted as January, February, March….etc. Instead of alphabetically. Looking at your image, that appears to be what is happening. The year is sorted but the months are being sorted by monthname rather than month number.
** Was this post helpful? Click Agree or Like below. **
** Did this solve your problem? Accept it as a solution! **1 -
Try this formula: DATE_FORMAT(STR_TO_DATE(LEFT(Date + hour, 8),'%Y%m%d'), '%Y-%m-%d')
STR_TO_DATE(LEFT(Date + hour, 8),'%Y%m%d') extracts the date portion in the format YYYYMMDD.
DATE_FORMAT() function converts the date into the YYYY-MM-DD format, which should be sortable.** Was this post helpful? Click Agree or Like below. **
** Did this solve your problem? Accept it as a solution! **0
Answers
-
It appears to be sorting…just not the sort you are looking for. When I do values using year & month, I create a monthname and a month (integer value). For example monthname(CURRDATE()) might give me "April". Whereas month(CURRDATE()) would give me "4". I put the monthname version on the card and put the month version on the sort. That way monthnames are sorted as January, February, March….etc. Instead of alphabetically. Looking at your image, that appears to be what is happening. The year is sorted but the months are being sorted by monthname rather than month number.
** Was this post helpful? Click Agree or Like below. **
** Did this solve your problem? Accept it as a solution! **1 -
Thanks @ArborRose for your help. I have tried it, but no matter what I put in the Sorting field it seems to ignore it and still sorts by a character version of what it finds in the X-axis. I have tried 202404 or the full date 20240424 in the Sorting but it still won't use it.
As far as the value in the X-axis it is supposed to be a Date, with no special formatting, because it is tied to the Global filter on the dashboard.
Alek
0 -
Try this formula: DATE_FORMAT(STR_TO_DATE(LEFT(Date + hour, 8),'%Y%m%d'), '%Y-%m-%d')
STR_TO_DATE(LEFT(Date + hour, 8),'%Y%m%d') extracts the date portion in the format YYYYMMDD.
DATE_FORMAT() function converts the date into the YYYY-MM-DD format, which should be sortable.** Was this post helpful? Click Agree or Like below. **
** Did this solve your problem? Accept it as a solution! **0 -
Thanks again for your efforts. Now it shows my calculated field as character "abc" and didn't change the sorting…
I'll try to add my date calculation to the ETL instead of the beast mode. I was trying to avoid it because it's someone else's dataset and transformation, but oh well at least it will hopefully do it.
I'll let you know the outcome.
Alek
0 -
As I thought only after I added it to the dataset in ETL it started sorting normally. Thanks again for your help @ArborRose !
1
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.6K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 102 SQL DataFlows
- 626 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 754 Beast Mode
- 61 App Studio
- 41 Variables
- 693 Automate
- 178 Apps
- 456 APIs & Domo Developer
- 49 Workflows
- 10 DomoAI
- 38 Predict
- 16 Jupyter Workspaces
- 22 R & Python Tiles
- 398 Distribute
- 115 Domo Everywhere
- 276 Scheduled Reports
- 7 Software Integrations
- 130 Manage
- 127 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 11 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 110 Community Announcements
- 4.8K Archive