Forum Discussion

Dicken's avatar
Dicken
Post Prodigy
1 year ago
Solved

Sorting Records

 

I wanted a way to sort a records without converting to a table ; I came up with this , 
if anyone has better solution or improvement I would be interested. 

 

 let
     rec = [ B = "abc", E = 12, D = "def", C = 10 , A = 5] ,

    orderby = Record.FromList( 
                 List.Repeat( {null} , Record.FieldCount( rec)), 
                         List.Sort( Record.FieldNames( rec),Order.Ascending)
                             )
  in orderby & rec

Richard 

 

  • You can try this...

    let
        rec = [ B = "abc", E = 12, D = "def", C = 10 , A = 5],
        sortFields = List.Sort(Record.FieldNames(rec)),
        sortRecord = Record.ReorderFields(rec, sortFields, MissingField.Ignore) 
    in
        sortRecord
  • Dicken's avatar
    Dicken
    1 year ago

    just to add, i did not know there was a re order , there are just so many m functions it's frightening.

3 Replies

  • You can try this...

    let
        rec = [ B = "abc", E = 12, D = "def", C = 10 , A = 5],
        sortFields = List.Sort(Record.FieldNames(rec)),
        sortRecord = Record.ReorderFields(rec, sortFields, MissingField.Ignore) 
    in
        sortRecord
    • Dicken's avatar
      Dicken
      Post Prodigy

      just to add, i did not know there was a re order , there are just so many m functions it's frightening.

    • Dicken's avatar
      Dicken
      Post Prodigy

      Thanks, had not thoiught of that.