Forum Discussion

SebSchoon1's avatar
SebSchoon1
Post Patron
4 years ago
Solved

Dynamic reordering of columns

Hi Guys,   I would like to know if it is possible to reorder columns dynamically?   I have all these orders corresponding to different "Types" of items which have different sizes accross th...
  • jennratten's avatar
    jennratten
    4 years ago

    Here are examples of how you can dynamically set the column order.  If you can provide an example/screenshots of what the size column names are and the outcome you are trying to achieve I can provide a more specific solution. 

    Match the column order for a different table:

    Table.SelectColumns ( #"Name of Previous Step", Table.ColumnNames ( #"Other Table Name" ) )

    Columns without "Size" in the name followed by columns with "Size" in the name:

    Table.SelectColumns ( #"Name of Previous Step", let
       varBufferedList = List.Buffer ( Table.ColumnNames ( #"Name of Previous Step" ) ),
       varColumnsWithoutSize = List.Select ( varBufferedList, each not Text.Contains ( _, "Size" ) ),
       varColumnsWithSize = List.Select ( varBufferedList, each Text.Contains ( _, "Size" ) ),
       varFinalColumns = List.Combine ( {varColumnsWithoutSize, varColumnsWithSize} ) in
    varFinalColumns )