Forum Discussion
Sort chronologically x axis based on date and time column
Hello all,
I built a scatter chart with a date and time column on the x axis, but I am having some problems sorting it by date. I have already tried to adapt some solutions for similar problems but I couldn't solve it yet.
My date column has the general format (14/03/2001 13:30:55) and when I select to sort the visual by this column, it does not sort it chronologically and I cannot understand how it is sorted. The first dates on the chart when sorting it ascending by date are:
- 05-09-2011 00:00:00
- 01-06-2011 00:00:00
- 07-09-2012 00:00:00
- 17-02-2012 00:00:00
- 09-09-2011 00:00:00
- 01-02-2012 00:00:00 ...
I tried to create a new column based on this one with the format "YYYYMMDDHNNSS" and sort the first column by this new one but it returned an error of circular dependency. I also thought to follow the same logic, but creating a new column with a sequence of numerical values in the same table sorted by the date column (since on the data tab date column is sorted correctly, chronologically), but I do not know how to do it neither if it makes sense.
Can anyone help me?
Thanks in advance.
Hello Anonymous ,
Thank you for your answer.
Comparing with your data, I thought everything was equal, but then I noticed that the problem was related to the legend. In fact, when I excluded it, dates are sorted chronologically.
I think the problem is related to the model structure. The chosen column for the legend is from another table. This table is not connected directly to the table that I'm using for the values on the y and x axis and the relationship between both tables are many to many. Now I'm trying to recreate the model to be possible to include the legend and keep x axis sorted chronologically.
Best regards,
18 Replies
- Pragati11
Super User
Hi valcat27 ,
First thing you haven't attached any screesnhots around you issue with the visual, do add it so makes the understanding better.
The column should be of DATETIME format. Check this again. Also share some screenshots from data where this column has date datatype.
Thanks,
Pragati
- valcat27
Helper III
Pragati11 and parry2k thank you for your answers.
The data that I can share is a bit limited, but I hope it is sufficient.
1)The figure below shows how the visual looks like and, as you can see, x axis is not sorted chronologically.
2) To sort the visual, on “More options” (…), I selected “Sort ascending” and “Sort by date column”.
3) On data tab/section, selecting the date column, in the table, I can verify that values are sorted chronologically and the column type is Date/Time.
- valcat27
Helper III
Yes, I’m sure. I also tried to change it to “sort by y –axis” to validate and the dates appear more random (than before) like 2018, 2019, 2016, 2014, 2019, 2019, 2019. Moreover, when I select “sort by date column” and “sort descending”, the first dates appearing in the visual are in fact the last years, but again sorted only partially chronologically.
- AnonymousNot applicable
- valcat27
Helper III
Hello Yuna,
Yes, it is. How can I do the same with my data?
- AnonymousNot applicable
Hi valcat27 ,
Actually I did nothing. I just created the date and imported it into Power BI Desktop. I suggest that you can modify your date format, because when I import the sample data, "17-02-2001" shows the TEXT format. Power BI Desktop currently cannot convert TEXT format to date format. You can modify the format of the date column of the data source to "mm/dd/yyyy". I tested the following sample data without any problems.
Hope that's what you were looking for.
Best Regards,
Yuna
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- valcat27
Helper III
Hello Anonymous,
I'm sorry, but I don't understand your solution. Where should I exactly change the format?
I imported my data directly from SQL Server and Power BI recognize this column's data type as date/time. On data left tab, I tried to change the data format to different formats, but the visual continues with the same incorrect sorting.
- AnonymousNot applicable
Hi valcat27 ,
Sorry for that I assuming you are using an Excel file as data source. Could you please share a screenshot of your date column in SQL server with me to show me more the date column details? What's the data type of your date column in SQL Server?
Best Regards,
Yuna
- AnonymousNot applicable
Hi,
Based on your description, I did a test. Unfortunately, I cannot reproduce your issue. Please verify that my steps are as follows. Is there anything I missed?
Best Regards,
Yuna
- valcat27
Helper III
Hello Anonymous ,
Thank you for your answer.
Comparing with your data, I thought everything was equal, but then I noticed that the problem was related to the legend. In fact, when I excluded it, dates are sorted chronologically.
I think the problem is related to the model structure. The chosen column for the legend is from another table. This table is not connected directly to the table that I'm using for the values on the y and x axis and the relationship between both tables are many to many. Now I'm trying to recreate the model to be possible to include the legend and keep x axis sorted chronologically.
Best regards,
- BenFNew Member
Hello,
I encouter the same issue : using a scatter chart with date as X-axis and it is not sorted chroinologically when I use a legend. I think I understood the sorting strategy. Power BI plots the first column type of the legend using the chronological order. If another type of the legend contains data on the same date it is also plotted in the chronological order. If there is no data on a given date of the first type it is skipped. Once first column is read, it follows with next column type,... Better than my explanation, hear is a picture that is probably easier to understand
However, I don't have the solution to solve this issue. The only thing I can think of is to create a fake null value on each date for all types but it doesn't seem to be a robust solution.
Does anyone have an idea on how to solve it.
Thanks in advance for you support.
Best regards,
Benjamin
- AnonymousNot applicable
Hi valcat27 ,
Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or you are still confused about it, please provide me with more details about your table and your problem?
Best Regards,
Yuna