Forum Discussion

Ania26's avatar
Ania26
Helper IV
9 months ago
Solved

sorting matrix

Hello, I would like to sort matrix table by Year and then by value for each Country. How to do it?

Country Year Value
Belarus 2024 19099
Belarus 2025 19023
Belarus 2023 17596
Paraguay 2024 11559
Paraguay 2025 11556
Paraguay 2023 242

  • Ania26 Sorry I just took another look at your picture and now I get what your issue is. You're currently sorting by the Value descending but actually want the dimensions ascending, right?

    Your current version probably looks similar to this:

     

6 Replies

    • Ania26's avatar
      Ania26
      Helper IV

      Hello, thank you but I want to see first Country and then Year

      • KarinSzilagyi's avatar
        KarinSzilagyi
        Super User

        Ania26 Sorry I just took another look at your picture and now I get what your issue is. You're currently sorting by the Value descending but actually want the dimensions ascending, right?

        Your current version probably looks similar to this:

         

  • In Power BI, the Matrix visual allows you to control sorting on multiple levels, but it behaves slightly differently from a normal table.
    If you want to sort by Year (in descending order) and then by Value within each Country, follow these steps:

     

    Option 1 – Sort using the visual menu

    • Click on the ellipsis (…) in the top-right corner of your Matrix visual.
    • Select Sort by → Year.
    • Then click the ellipsis (…) again and choose Sort by → Value.
      Power BI will apply sorting hierarchically within the Matrix, starting from the outer field (Country → Year → Value).

     

    Option 2 – Use a calculated sort column
    If the sorting still doesn’t display as expected, create a calculated column in your data model:

     

     

    SortOrder =
    RANKX(
    FILTER(
    'Table',
    'Table'[Country] = EARLIER('Table'[Country])
    ),
    'Table'[Value],
    ,
    DESC
    )

     

    Option 3 – Sort the Matrix manually
    You can also click directly on the column headers (Year or Value) in the Matrix visual.
    Power BI lets you click twice to switch between ascending/descending order for that level.

     

    Each Country will appear as a separate group (like Belarus and Paraguay in your screenshot), and inside each group, years will be sorted correctly with the corresponding values.

     

     

    I hope it will help you. If so, please give kudoes and accept it as a solution. Thanks

  • v-hjannapu's avatar
    v-hjannapu
    Community Support

    Hi Ania26.,

    I would also take a moment to thank Ilgar_Zarbali  , KarinSzilagyi  for actively participating in the community forum and for the solutions you’ve been sharing in the community forum. Your contributions make a real difference.
     

    I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions.

    Regards,
    Community Support Team.

    • v-hjannapu's avatar
      v-hjannapu
      Community Support

      Hi KarinSzilagyi,
      I hope the above details help you fix the issue. If you still have any questions or need more help, feel free to reach out. We are always here to support you.


      Regards,
      Community Support team.