Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Sorting a text/number column in matrix - not sorting correctly

Hi guys

 

I have a matrix visualisation with a text field that includes both numbers and text. I have tried soring it the 'normal' way where i go to the "..." in the visual and choose "Sort by" and then select my field - but the values dosent sort correctly all the way. 

 

I know of the leading zero solution, but that is not the problem here unfortunately. 

 

If it matters then the field im trying to sort is the second value in the 'rows'. 

 

I really hope you can help me, and thank you in advance 🙂

 

  • It could be a combination of those account numbers being text and numbers. I see that all of the time when importing GL data from files.

     

    I would create a sorting only column in Power Query. Just add a custom column and ensure it is a number. For example, 

    1. Add this column - Call it "Account Sort" or something: =try Number.FromText([Account]) otherwise null
      1. Set the data type for that column to Whole Number
    2. Filter this column to show only NULL values. You should have none. If you do, that is another issue to resolve.
    3. Remove your NULL filter. That was just to see what was there.
    4. Load into the data model
    5. Once in the reporting section of Power BI, see image below
      1. Select the report tab
      2. Select your Account column
      3. Select the Column Tools tab and Sort By Column
      4. Select Account Sort or whatever you called this new field.

     

     

     

    If that doesn't work, please post back with some sample data so we can play with it.

9 Replies

  • edhans's avatar
    edhans
    Community Champion

    It could be a combination of those account numbers being text and numbers. I see that all of the time when importing GL data from files.

     

    I would create a sorting only column in Power Query. Just add a custom column and ensure it is a number. For example, 

    1. Add this column - Call it "Account Sort" or something: =try Number.FromText([Account]) otherwise null
      1. Set the data type for that column to Whole Number
    2. Filter this column to show only NULL values. You should have none. If you do, that is another issue to resolve.
    3. Remove your NULL filter. That was just to see what was there.
    4. Load into the data model
    5. Once in the reporting section of Power BI, see image below
      1. Select the report tab
      2. Select your Account column
      3. Select the Column Tools tab and Sort By Column
      4. Select Account Sort or whatever you called this new field.

     

     

     

    If that doesn't work, please post back with some sample data so we can play with it.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi edhans 

       

      I actually allready had only the number part seperated - it was a wish from the customer to have the text part included in the field. 

       

      I tried sorting after that using your method and it worked 

       

      Thank you so much 🙂

      • edhans's avatar
        edhans
        Community Champion

        Excellent Anonymous . The Sort By Column feature can be super handy sometimes.

  • Hi Anonymous ,

     

    Based on my tests I was abble to sort everything correctly however my data is just based on your small sample.

     

    Can you share a sample file?

     

    Regards,

    MFelix

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi MFelix 

       

      Thank you for your reply

       

      Im unfortunately not allowed to share the file, but is there any other information i can give you?

  • mussaenda's avatar
    mussaenda
    Community Champion

    If you are using matrix visual, it will not sort on your desired column.

     

    A workaround is sorting it in powerquery then applying it.

    How this helps.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi mussaenda 

       

      Thank you for the reply

       

      I tried to sort the column in the powerquery, but it is still not sorting in the matrix