Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Administrator
2 years ago

sort column according to another

I want to sort column1 by the numbering of column2 and I get the following error
How could I solve it?

Column1Column2
albert1
albert1
juan3
manuel4


thank you.

5 Replies

  • You can initially make the column 1 as distinct first in PowerQuery then load. You can now sort the column1 by column 2. After that back to Powerquery then remove the step that make the column1 distinct and apply. Sorting still applies

     

     

    • Syndicate_Admin's avatar
      Syndicate_Admin
      Administrator

      I try to sort having modified the values in the description column but I keep getting an error, I can't find the why.

      Thank you.

  • halfglassdarkly's avatar
    halfglassdarkly
    Responsive Resident

    You haven't stated what error you're seeing, but typically in this scenario if you're calculating the value of Column2 based on Column1 and then trying to sort Column1 by Column2 it will give a circular dependency error.

     

    The way I'd normally deal with this is to generate Column1 as an ordered/ranked list, then generate Column2 based on Column1 omitting the value you are using for ranking.

     

    E.g. if your value In Column1 was '1 albert' then you could create column 2 using:

     

    Column2 = MID([Column1],FIND(" ",[Column1],1)+1,100)

     

    Then sort Column2 by Column1.

     

    However since you're sorting a string you may need to add leading zeros to get it to sort correctly. E.g. 

     

    02

    12

     

    if you want the 2nd item to rank before the 12th.

     

     

  • manvishah17's avatar
    manvishah17
    Solution Supplier

    Hi Syndicate_Admin , 
    In your case sorting one column1 by  col 2 will give errror as col 2 have same values for two values of col 1

    (look your row 1and 2 so....)

    If you can replace any value then you can perform sorting easily like this ,

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Syndicate_Admin ,

     

    Trying to sort by index via power query so that each row of data is not duplicated and then sorting it.

     

    Hope it helps!

     

    Best regards,
    Community Support Team_ Scott Chang

     

    If this post helps then please consider Accept it as the solution to help the other members find it more quickly.