Forum Discussion
Conditionally rename columns
- Anonymous5 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
You can adapt the approach described in this video to dynamically rename your columns with relative references (e.g., rename the first column to "Column1" and the second to "Column2"). You can use Table.ColumnNames(#"Previous Step"){0} for example to get the name of the first column from the previous step (replace Previous Step with the actual step name), and you can use that in place of your current hard-coded column name.
(3) Power BI - Use relative references to avoid combine & transform errors - YouTube
Pat