Forum Discussion

ValeriaBreve's avatar
ValeriaBreve
Post Partisan
3 years ago
Solved

combining Excel files with dfferent columns

Hello! I am trying to combine Excel files in Powerquery that have different columns: The year will always change, and that bit I was able to somehow capture dynamically based on the column position...
  • jennratten's avatar
    jennratten
    3 years ago

    Hello - yes, this is possible.  You would just change the portion of the script that removes columns to only remove those that have duplicates, not to remove the empty columns.

    BEFORE

        // Combine duplicate plan columns and generic columns into one list.
        ColumnNamesToRemove = List.Combine ( { DuplicatePlanColumns, GenericColumnNames } ),
        // --------------------------------------------------------
        // Clean up the column names. 
        // --------------------------------------------------------
        // Remove specific columns from the source table.
        RemoveColumns = Table.RemoveColumns ( Source, ColumnNamesToRemove ),

    AFTER

        // Combine duplicate plan columns and generic columns into one list.
        // ColumnNamesToRemove = List.Combine ( { DuplicatePlanColumns, GenericColumnNames } ),
        // --------------------------------------------------------
        // Clean up the column names. 
        // --------------------------------------------------------
        // Remove specific columns from the source table.
        RemoveColumns = Table.RemoveColumns ( Source, DuplicatePlanColumns),