Forum Discussion

michaelsh's avatar
michaelsh
Kudo Kingpin
5 years ago
Solved

Conditionally rename columns

I am getting inconsistent column names from my source files. Sometimes, one column's name is "Document Type", sometime, it is "Document type", with a small "t". Sometimes, another column's name is ...
  • Anonymous's avatar
    Anonymous
    5 years ago

    All you have to do is use Table.RenameColumns, and add the renames whether or not that table's column names are correct or not, because you can add the MissingField.Ignore parameter. So in your Transform file, after you've promoted headers, or at whatever point your column names are in place, add this as your next step:

     

    = Table.RenameColumns(PriorStepName, {{"Document type", "Document Type"}, {"Amt. in loc. curr.", "Amount In Local Currency"}, {"Another bad name", "Another Bad Name"}}, MissingField.Ignore)

     

    If the column name is incorrect, it'll get corrected. If it's already correct, then the misspelled column is not present in that table, and will be ignored.

     

    --Nate