How to sort multiple columns using the M Language in Power Query

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 พ.ย. 2024

ความคิดเห็น • 68

  • @Milhouse77BS
    @Milhouse77BS 5 ปีที่แล้ว +19

    Sorry, but you can accomplish the same with the GUI by sorting on first column, then sort again on the second column. It combines the two sorts into one step. :). Just tried on a test sheet.

    • @CurbalEN
      @CurbalEN  5 ปีที่แล้ว +3

      Great, thanks for sharing! Will pin the post for more visibility:)
      /Ruth

    • @brianxyz
      @brianxyz 5 ปีที่แล้ว +8

      Also, if you look closely you'll see a little number appear by the sort arrow which indicates the order in which the column was sorted: "1" for first, "2" for second, etc.

    • @danilochavez4167
      @danilochavez4167 5 ปีที่แล้ว +3

      There is a problem with this approach if your goal with the sorting is to eliminate a duplicate register. Once I wanted to keep the top row after a few sorting and eliminate the duplicates and power query couldn't make it. You could see it correct on the editor but not on the resulting table. I read that you have to index the database before the sorting to make the trick but it didn't work for me. Maybe Ruth you have a different approach to this issue? Thanks for all your videos Ruth. You have helped me a lot and I wish you the best. Keep this amazing work you do for us!

    • @vikrammankar4083
      @vikrammankar4083 3 ปีที่แล้ว

      But the problem is my sorting is on 2 columns which is in two different tables. Date is in Calendar Table & Amount is in Sales Table. If they both would have been in single table this could have been achieved.

    • @EnkhturDamdinjav
      @EnkhturDamdinjav 2 ปีที่แล้ว

      what do you mean with GUI?

  • @charliemather3368
    @charliemather3368 5 ปีที่แล้ว +8

    Ruth, It is not necessary to edit the M code. If you sort by the first column and then during the same step you sort by an another column, the same M code is created showing the two columns on the same step such as:
    = Table.Sort(#"Changed Type",{{"Company State", Order.Ascending}, {"Company City", Order.Ascending}})

  • @shakeelmusicdotcom
    @shakeelmusicdotcom 4 ปีที่แล้ว

    Hi Curbal, thanks for this video very helpful!
    To add to this, e.g. for the folks that also want to have the table sorted in the 'Table Visual':
    1) First sort the table in the query editor as explained in the video
    2) Hereafter go to 'Add column' and add an 'Index Column'
    3) Click apply
    4) Create your visual (e.g. Table) add the Index Column and sort on Index.
    In addition, I learned that the newest version of Power BI now has a built in feature to sort on multiple columns (shift+click), I will update and check it out soon.

  • @rodrigomdfranca
    @rodrigomdfranca 3 ปีที่แล้ว

    I speak of Brazil, I looked for this help a lot I am very grateful, God bless!

  • @rrrraaaacccc80
    @rrrraaaacccc80 ปีที่แล้ว +1

    Excellent explanation 💯👍

  • @diegolozano2397
    @diegolozano2397 3 ปีที่แล้ว

    Thanks a lot, a bog hug from colombia 🇨🇴🇨🇴🇨🇴🇨🇴

  • @russo6770
    @russo6770 3 ปีที่แล้ว

    it did work for me, even I deleted columns after and it kep the sort , Thank you!!!

    • @CurbalEN
      @CurbalEN  3 ปีที่แล้ว

      🥳🥳

  • @fernandoatlahuarockefeller2162
    @fernandoatlahuarockefeller2162 7 หลายเดือนก่อน

    You are the G.O.A.T! Thank you so much!

  • @joangarcia6327
    @joangarcia6327 ปีที่แล้ว

    Easy, quick and superuseful. My favorites! Thank you.

  • @dinadulce
    @dinadulce 3 ปีที่แล้ว

    Thanks Curbal, I saw that the version Mar 2020 can do Shift+left click but I am using Sep 2019 in my work laptop so your video helped!

  • @JoshLundmark
    @JoshLundmark 2 ปีที่แล้ว

    Thanks! That is what I was looking for!

    • @CurbalEN
      @CurbalEN  2 ปีที่แล้ว +1

      🎊🎊

  • @joseblazquez2178
    @joseblazquez2178 5 ปีที่แล้ว +1

    Muy bueno Ruth! Muchas Gracias!, te saludo desde Houston
    -Jose

    • @CurbalEN
      @CurbalEN  5 ปีที่แล้ว

      Hola José, muchos saludos !!
      /Ruth

  • @gagansingh3481
    @gagansingh3481 2 ปีที่แล้ว

    Awesome mam keep posting M language tricks 😀

    • @CurbalEN
      @CurbalEN  2 ปีที่แล้ว

      Miss posting those, should get back at it :)

  • @madiakns
    @madiakns 5 ปีที่แล้ว +1

    Hi Ruth, we can select multiple columns with holding "Ctrl" button to sort multiple column.

    • @CurbalEN
      @CurbalEN  5 ปีที่แล้ว

      That doesn’t work for me. Does it for you?
      /Ruth

    • @steinarbreivik1895
      @steinarbreivik1895 4 ปีที่แล้ว

      @@CurbalENIn my version I need to hold both Shift and Ctrl, then it works. In previous version I only needed Ctrl.

    • @CurbalEN
      @CurbalEN  4 ปีที่แล้ว

      That is weird, but thanks for letting us know!

    • @chubbydawme
      @chubbydawme 3 ปีที่แล้ว

      @@steinarbreivik1895 Doesnt work. Holding shift and ctrl will select the columns and the columns in between the two columns.

  • @saravanapriyasivakumar4318
    @saravanapriyasivakumar4318 ปีที่แล้ว

    Hi Curbal, How to remove the sort option? I want the table to be displayed as same as how it is in source file. Please answer..

  • @CarlosGancedo
    @CarlosGancedo 3 ปีที่แล้ว

    Gracias era lo que necesitaba.

    • @CurbalEN
      @CurbalEN  3 ปีที่แล้ว

      Perfecto!

  • @EnkhturDamdinjav
    @EnkhturDamdinjav 2 ปีที่แล้ว

    this was useful, thanks

  • @sadinenim5360
    @sadinenim5360 2 ปีที่แล้ว

    Hi Curbal ,
    I think when we are sorting multiple columns we need to add Table.Buffer(Table sorting M Code) in the M code otherwise it won't do sorting properly. Do a video on Lazy Evaluation concept in power Query

  • @alreadydeadfunk
    @alreadydeadfunk 5 ปีที่แล้ว

    You can also use List.Transform, turning list of columns

    • @CurbalEN
      @CurbalEN  5 ปีที่แล้ว

      Thanks!
      /Rutj

  • @ayobamiologun9184
    @ayobamiologun9184 5 ปีที่แล้ว

    Thanks for sharing this tip Ruth.

    • @CurbalEN
      @CurbalEN  5 ปีที่แล้ว

      My pleasure 😇
      /Ruth

  • @giovani6666
    @giovani6666 5 ปีที่แล้ว

    what a fantastic tip! thank you so much Ruth !

    • @CurbalEN
      @CurbalEN  5 ปีที่แล้ว

      Thanks Giovani! Make sure you check the pinned comment to see an easier way :)
      /Ruth

  • @venkatareddykummitha5863
    @venkatareddykummitha5863 2 ปีที่แล้ว

    I need to create separate sorting custome column by country like US =1, England =2, like that in power query editor. Give me the links

  • @neilgore
    @neilgore 2 ปีที่แล้ว

    Super .. thanks

  • @marcelocabral5096
    @marcelocabral5096 2 ปีที่แล้ว

    great video, tks :)

  • @jeffhutchinson974
    @jeffhutchinson974 3 ปีที่แล้ว

    What is the result of the sort? It seems to only be useful in the Power Query editor. There does not seem to be any effect in Power BI Data view or when you add a field to a table.

  • @longgnolgmail
    @longgnolgmail 4 ปีที่แล้ว +1

    Hi Ruth, I’m made the sort change in power query, clicked close/apply, but when I create a new Table Visualization, it still only sorts one column at a time. Am I missing a step?

    • @rajip9630
      @rajip9630 4 ปีที่แล้ว +1

      I have the same problem. if I click close and apply, in the visual I am seeing only one column is sorted in descending and no change in another column. I appreciate your help.

    • @samersammour6801
      @samersammour6801 4 ปีที่แล้ว

      Same here! When I close & apply the table in Power Pivot doesn't sort according to Power Query

  • @KamranMumtazAhmed
    @KamranMumtazAhmed 2 ปีที่แล้ว

    Rather than writing or copying and pasting and then changing the column name, why don't you just sort the columns one by one to save time? Is there any particular reason not to do this?
    Curious to know about it. TIA.

  • @brv1111
    @brv1111 3 ปีที่แล้ว

    Thanks!!

  • @EricaDyson
    @EricaDyson 5 ปีที่แล้ว

    Another useful tip! Thanks so much!

    • @CurbalEN
      @CurbalEN  5 ปีที่แล้ว

      Check the pinned comment for an easier way :)
      /Ruth

  • @kusalamarasena3882
    @kusalamarasena3882 4 ปีที่แล้ว

    Hi Ruth,
    I have sorted my data as per your video.but it doesn't appear on the table view.it always shows ascending order by date.. there is no any sort other than power query sort.
    please help me to sort this out.

  • @MaisQuePlanilhas
    @MaisQuePlanilhas 5 ปีที่แล้ว

    Nice Trick! i’ll record in portuguese in my channel for brasilians learning it! i’ll give your credits!

    • @CurbalEN
      @CurbalEN  5 ปีที่แล้ว +1

      Thanks 👊, but before you do that, check the pinned comment, there is a easier way to do this :)
      /Ruth

  • @PedroCabraldaCamara
    @PedroCabraldaCamara 5 ปีที่แล้ว

    great trick Ruth!

    • @CurbalEN
      @CurbalEN  5 ปีที่แล้ว

      Hi Pedro,
      Make sure you check out the pinned comment for an easier way :)
      /Ruth

  • @Bigsarl
    @Bigsarl 5 ปีที่แล้ว +1

    Useful tips as usual, thank you.
    Naji K.

    • @CurbalEN
      @CurbalEN  5 ปีที่แล้ว

      Hi Naji!
      Make sure you check out the pinned comment for an easier way :)
      /Ruth

  • @saradachoudhury8732
    @saradachoudhury8732 3 ปีที่แล้ว

    I have a unique requirement. The requirement is when no filter is selected the text graph should be sorted by Date column. Or when Country filter is selected the text graph should be filtered by sales. Could you please help me how to achieve it.

  • @EricaDyson
    @EricaDyson 5 ปีที่แล้ว

    Actually Ruth, I'd be pleased if you could go through auto-indexing. I'm used to Access where if I append a query, auto indexing will give new rows a an ID. But how does this work in Power BI? I don't want to give old data new indexes, I just want new data to have an index-ID. So what do I need to do? Hopefully, I'm not the only one who doesn't know what best practice is!!

    • @CurbalEN
      @CurbalEN  5 ปีที่แล้ว

      Hi Erica,
      What are you using the index columns for ?
      /Ruth

    • @EricaDyson
      @EricaDyson 5 ปีที่แล้ว

      @@CurbalEN Well I just feel I should have one, shouldn't I? Although, for cities, for example, I have a unique ID and that would be appended, but I thought that all my tables should have them.. maybe not?!

    • @CurbalEN
      @CurbalEN  5 ปีที่แล้ว

      If your table contains a column with unique values, then you don’t need an index, it will only hurt your performance. Should definitely make a video on this!
      /Ruth

    • @EricaDyson
      @EricaDyson 5 ปีที่แล้ว

      @@CurbalEN Yep.. I know that, but what about the tables that don't have unique values?

    • @CurbalEN
      @CurbalEN  5 ปีที่แล้ว

      Then you need an Id ;)
      /Ruth