Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
Jolyon
Helper III
Helper III

how to sort Date (MonthYear column)?

Hello,

need urgent help of yours:

 

I have a column Date (e.g. 01.01.2016), then I added columns Month and Year and concatenated them to get the column MonthYear(e.g. January2016):
6.png

 

 

Now the problem is, that I have date from 3 years(2016-2018) and I can not sort them correctly:
5.png


Here I sorted them by Month Number, but as you see, it doesn't work correctly. I can not sort them by column Date either, since I have multiple Date values for one MonthYear value.


So how could I sort MonthYear correctly, so that values Jan2017 and Feb 2017 will be shown after Months of 2016?
Could anyone help?

thanks a lot!

22 REPLIES 22
theov
Advocate II
Advocate II

You can make a calculated column and magnify year's importance by multiply to 100 and add month and sort your column by new column. I'd rather put year month 🙂 Here is a comprehensive video about calendar in power BI also :

https://www.youtube.com/watch?v=Oq5WOmo94_Q

Anonymous
Not applicable

An elegant solution is to create a date bin. You do this by

 

  1. Right click on data field (make sure it's a date type)
  2. Select 'New Group'
  3. Create Bins (could be more than one month if you wish)
  4. choose the new bin for your 'shared axis' in the Report View
  5. win

bins.screencap.png

It worked for me also what i have done is i have created the bin and then sorted the actual column by data-bin (which is created )

The solution is awsome. After so many solutions, sort by column etc, this works for me. But one thing I don't understand why we can not customize the Min value & Max value? Mine, it is auto set Min 1/1/2020 Max 31/12/2021, it is not quite right if I want the data before 1/1/2020?

I have been struggling with this for a while and this is so easy. Isn't that always the way eh! Thanks very much.

Anonymous
Not applicable

this worked for me

Anonymous
Not applicable

And remember to check that your date column is well based on "DATE" type otherwise it may not work 

Viha
New Member

Hi @tringuyenminh92,

 

Tried setting up the Sort by Column but my table and charts still didn't sort properly.  I followed the steps and the YearMonthInt formula worked. What am I missing?

YMI.PNGChart.PNGTable.PNG

 

EdwinRotgans
New Member

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
DateMonthYearShortDateInt
01.01.2017jan.1720170101
15.01.2017jan.1720170115
29.01.2017jan.1720170129
12.02.2017feb.0720170212

 

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:

 

YearMonthIntFORMAT ( Dates[Date]; "YYYYMM" )  // or any other format that suits your text column

 

 

 

Date Table
DateMonthYearShortDateIntYearMonthInt
01.01.2017jan.1720170101201701
15.01.2017jan.1720170115201701
29.01.2017jan.1720170129201701
12.02.2017feb.0720170212201702

 

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

 

 

 

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.

new'.JPG

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.

Anonymous
Not applicable

Thanks it worked for me.

tringuyenminh92
Memorable Member
Memorable Member

Hi @Jolyon,

 

In case you want to sort by Year and Month of date, you could add Calcuated column for YearMonthInt as:

YearMonthInt = Dates[Date].[Year]*100 +  Dates[Date].[MonthNo]

Then choose MonthYear column and choose sort by YearMonthInt column.

 

2016-12-15_14h57_39.png

 

If this works for you please accept it as solution and also like to give KUDOS.

Best regards
Tri Nguyen

wow this is one of the question from PL-300 certifications!

where do you learn this?

Wow, I'd been looking what felt like everywhere for an answer to this problem, somehow no other site or video suggested that trick of multiplying the year by 100, that's what made it work for me. More than three years after you wrote the post, too. Thanks!

Worked for me so thank you @tringuyenminh92 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

 This worked for me!  Thanks!

Anonymous
Not applicable

Sorting .jpg

Hi @tringuyenminh92 I am having this kind of data in reports and also wnat to sort as same @Jolyon sorting for his reports 

means if multiple years data we have first it will sort by year in that case . But how to prepared calculate colum for above scenario as per above data. help me here i am new to DAX querys. also not having date column in my all tables so please suggest me how to achive that sorting on multiple year data  

 

hi @tringuyenminh92
could you please also tell, how you concatenated MonthYear?

Question to this formula:   YearMonthInt = Dates[Date].[Year]*100 +  Dates[Date].[MonthNo]  : is Dates the name of table? "Year" and "MonthNo" are your columns or DAX functions?

because in my case PowerBI underlines this formula as red: YearMonthInt = Client[Datum].[Jahr]*100 +  Client[Datum].[Mon]

 

thank you kindly!

When we cast Date column to Date type, PBI will suport us to access its Month (month name) and Month value (MonthNo)

My MonthYear= Dates[Date].[Month] & "-" & Dates[Date].[Year]

I think your expression of YearMonthInt is correct, just choose sort by column.

 

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

Check out the October 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

Find out what's new and trending in the Fabric Community.