Forum Discussion
Simple Way to Handle Column Renames in Power BI?
- 1 year ago
Hey,
I think it should be enough if you add a step in power query to rename the columns using the mapping table, you should try to add this step
= Table.RenameColumns(PreviousStep, List.Zip({MappingTable[OldColumnName], MappingTable[NewColumnName]}), MissingField.Ignore)I created an example PBIX file for you (attacched). Feel free to check it out.
Hi Nazdac2024
When you rename a column in Power Query, it works with a list of lists. For example:
{{"SheetorRangeId", "SheetorRangeId2"}, {"Data", "Data2"}}
That’s the structure you’re trying to replicate.
If you already have a query that contains your column name mappings, you can reference those directly. Just make sure the columns you’re renaming actually exist in the table:
= Table.RenameColumns( #"Previous Step Name", List.Zip({MappingTable[OldColumns], MappingTable[NewColumns]}) )
Here, MappingTable[OldColumns] and MappingTable[NewColumns] each become a list (a single column of values). Table.RenameColumns needs these pairs of old name - new name to sit next to each other. That’s where List.Zip comes in - it takes the two separate lists and stitches them together row by row, just like zipping up a jacket where each tooth from one side lines up with the matching one on the other.