Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

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
  • Anonymous's avatar
    Anonymous
    4 years ago

    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.

     

    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!

     

     

4 Replies

  • 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:

     

     

    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
     
  • ValtteriN's avatar
    ValtteriN
    Icon for Community Champion rankCommunity Champion

    Hi,

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


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

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


    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!

    • Anonymous's avatar
      Anonymous
      Not applicable

      I want something like below

       

       

  • Anonymous's avatar
    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.

     

    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!