Forum Discussion
Problem with months not in order on line chart
I have a line chart with data showing number of X vs date. However, I have a problem where two of the months are flipped (see image). I have looked into this community and found similar threads. The solution I read many times was to sort my time by the date column. However that has not worked for me. Someone mentioned changing the x-axis to conitnuous but my chart won't allow me to do that and I don't have a dates table as some mentioned is need for continuous x-axis. Does anyone have any other solutions for this issue?
Line chart
Ok. without something to work with it is difficult to assist. But let me try one more thing.
Download this PBIX file. It has some random data I put together for 2020. Notice how the chart is not sorted by month properly. I'm not sure how it is sorted. It isn't alphapbetical or by date. Do the following:
- Click on the Month Name field in the Date table.
- Click on the Column Tools menu (this is the new ribbon)
- Click Sort By Column
- Pick "Month" which is an integer from 1-12 that perfectly corresponds to Jan-Dec.
- In your chart, click the elipses and ensure it is being sorted by Month Name, not Sales.
Ensuring the chart is sorting correctly.
It should now be sorted by the Month Name, which in turn is sorted by the numerical month number.
See if walking through that process helps. I don't know what else to do if I cannot have access to your PBIX file to more closely examine the issue.
14 Replies
- edhans
Community Champion
You do not have to sort by a date column, but you do have to provide a sortable column in your data set so Power BI knows how to sort. A date table is far and away the best practice here, but you can use any column to sort. See this article.
If you cannot get it to work, can you share your PBIX file via OneDrive or other method so someone can take a look at it? There is no workaround here. Sort By Columns is the thing. Period.
- amitchandak
Super User
If you only want shown month name then it better than you come by date hierarchy drill. Else preferably have month year and month year sort in your table and use that.
Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Connect on Linkedin - v-kelly-msft
Community Support
Hi jhern90 ,
Go to "edit queries">"Add column">"Index Column ">" from 1":
Then go back to data view>choose date column>sort by [Index]:
This would help.
Best Regards,
Kelly- jhern90Frequent Visitor
v-kelly-msft , I tried your suggestion but couldn't make it work. When I tried to sort the date column using the index column I got an error saying that I cannot sort it because there are multiple values in the index column for the same value in the date column. My data has multiple rows with the same date. Maybe this is my problem. Unfortunately I cannot get rid of them since they are different records, the other columns have different values, they just happen to have the same date. Do you know of a workaourd for this?
- edhans
Community Champion
You have to have 1 value per sorting value. So if you are sorting by month, January would be 1, February would be 2, etc. By doing the Index, January may have gotten 1, and 13, and 27, etc.
- In Power Query, click on the date column
- Click on the Add Column tab in the ribbon
- CLick on the dropdown under date, and click on Month, then Month again. Now all January's have 1, Feb have 2, etc.
- Sort by that column in the DAX model.