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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Sort by Year and Month

Hi All,

 

I have a table mentioned as below, I would like to sort it based on year and Month Number.  how can i achieve it in DAX query or Powe BI visual

YearMonthMonth Number
2020August12
2021September1
2021October2
2021November3
2021December4
2021January5
2021February6
2021March7
2021April8
2021May9
2021June10
2021July11
2021August12
2022September1
2022October2
2022November3
2022December4
2022January5
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous,

 

Please try this column.

 

 

Rank = 
RANKX(
    'Table',
    RANKX('Table','Table'[Year],,0)
    +DIVIDE(RANKX('Table','Table'[MonthNumber],,1),COUNTROWS('Table')+1)
)

 

 

The result should be like this.

vcgaomsft_1-1643008293823.png

 

Best Regards,

Community Support Team _ Gao

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

 

 

View solution in original post

4 REPLIES 4
Richard_100
Resolver I
Resolver I

Hello

 

My preference is usually to use calculated columns on the raw table to produce columns that can be sortable in one go, or dropped onto graph axes with no worries:

 

Richard_100_0-1643035036742.png

 

A text formatted version that can be sorted A-Z:

Sort Option 1 = 'Table'[Year] & " " & FORMAT('Table'[Month Number], "00")
 
A date formatted version, basically creating a date field with the 1st of the month, to be sorted oldest-to-newest:
Sort Option 2 = DATE('Table'[Year],
SWITCH([Month], "January", 1, "February", 2, "March", 3, "April", 4, "May", 5, "June", 6, "July", 7, "August",8, "September", 9, "October", 10, "November", 11, "December", 12)
, 1)
 
Hope that helps
 
Regards
Richard
 
Anonymous
Not applicable

Hi @Anonymous,

 

Please try this column.

 

 

Rank = 
RANKX(
    'Table',
    RANKX('Table','Table'[Year],,0)
    +DIVIDE(RANKX('Table','Table'[MonthNumber],,1),COUNTROWS('Table')+1)
)

 

 

The result should be like this.

vcgaomsft_1-1643008293823.png

 

Best Regards,

Community Support Team _ Gao

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

 

 

ValtteriN
Super User
Super User

Hi,

You can sort columns by pressing the "sort by column" as seen on this picture: 

ValtteriN_0-1642683432834.png


You can e.g. sort your Year and Month Columns based on date.

For visuals you can sort data py pressing the ...

ValtteriN_1-1642683537951.png


I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!





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

Proud to be a Super User!




Anonymous
Not applicable

I want something like below

 

TamilselviK_0-1642683900813.png

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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