Reorder Columns with changing number of columns RRS feed

  • Question

  • Hello all,

    I am creating a table through 2 different queries:

    • Query A: Get a column from a table, remove duplicates, transpose
    • Query B: Get a column from a table, remove duplicates
    • Append B into A
    • Reorder columns so that B is the first column (problem step)
    • Promote first row as header so that query A is actually turned into headers

    What I can't solve is that when Query A is brings different number of columns, reorder gives errors like Column3 is not found.

    How do i handle this error?


    Thursday, September 13, 2018 8:16 AM


  • If the number of columns is unpredictable, I'd recommend doing something like the following:

    = Table.ReorderColumns(PreviousStep, List.Intersect({{"Column3", "Column1", "Column2", "Etc."}, Table.ColumnNames(PreviousStep)}))

    The list of Column3, Column1, etc. should be the list of all columns you ever expect to get, in the order you would like to see them. The List.Intersect call will remove any items from this list that don't exist in the table returned by the previous step.


    Friday, September 14, 2018 8:20 PM