Forum Discussion
how to sort Date (MonthYear column)?
For others with similar problems:
How to arrange PowerBI date labels chronologically:
If a Visual is distored because the date labels are aranged aphabetical (e.g.: April 2017; August 2017; .. ) instead of chronological (e.g. January 2017; February 2017), then you need to sort your datelabels column by a chronological column on the same table.
The easiest way is to create a new column with an int representation (e.g. 201701) of the datelabels column (January 2017) that you want to sort chronologically. Next, sort you column by the new column that contains the int values.
Example:
| Date Table | ||
| Date | MonthYearShort | DateInt |
| 01.01.2017 | jan.17 | 20170101 |
| 15.01.2017 | jan.17 | 20170115 |
| 29.01.2017 | jan.17 | 20170129 |
| 12.02.2017 | feb.07 | 20170212 |
Unfortunately, it is not possible to sort the MonthYearShort column by a column such as Date or DateInt because every value needs to match exactly one value in the column that will be sorted by. So you need to add a new column:
YearMonthInt = FORMAT ( Dates[Date]; "YYYYMM" ) // or any other format that suits your text column
| Date Table | |||
| Date | MonthYearShort | DateInt | YearMonthInt |
| 01.01.2017 | jan.17 | 20170101 | 201701 |
| 15.01.2017 | jan.17 | 20170115 | 201701 |
| 29.01.2017 | jan.17 | 20170129 | 201701 |
| 12.02.2017 | feb.07 | 20170212 | 201702 |
Now each datelabel matches one int value: jan.17 => 201701; feb.17 => 201702
The next step is to select the text column (MonthYearShort) and click Sort By and select the int column YearMonthInt, see link:
https://docs.microsoft.com/en-us/power-bi/desktop-sort-by-column
- ajsingh8 years agoFrequent Visitor
hey tringuyenminh92 you did a great gob in finding the trick for this common issue. Congratulations!!
I have a small issue, i did created similar kind of column and i did sorting also based on that column but my visuals are not getting sort, based on the new column rather i can't see any effect on my visuals.
If possible, post some sollution for it.
Thanks in advance.
- tringuyenminh928 years ago
Memorable Member
Hi ajsingh,
After setting up by "sort by column", in the top right of chart (icon: "..."), please choose sorting by the field MonthYear, then it will be sorted in chart.
- Anonymous6 years agoNot applicable
Thanks it worked for me.