Forum Discussion
PQ - Rename Column Names based of column names from another table
- 8 years ago
You were pretty close already:
#"Rename Columns" = Table.RenameColumns(Table2, List.Zip( { Table.ColumnNames(Table2), Table.ColumnNames(Table1) } ) )
Dealing with multiple tables in a query is tricky outside of a Merge or Append but ImkeF might have a trick for it.
You were pretty close already:
#"Rename Columns" = Table.RenameColumns(Table2, List.Zip( { Table.ColumnNames(Table2), Table.ColumnNames(Table1) } ) )
- Anonymous4 years agoNot applicable
Hello Imke,
I tried to use your code for a similar approach, but got the same error as 'vancromy': "Expression.Error: We expected a RenameOperations value".
As I´m quite a M-code beginner, I hope you´ve some time to bring me on the right track for a solution.The code I used is:
rename_table = Table.PromoteHeaders(Table.Transpose(ProjectLabels_indexed), [PromoteAllScalars=true]),
#"Rename_Columns" = Table.RenameColumns(#"Reordered Columns", List.Zip( { Table.ColumnNames(#"ReorderedColumns"), Table.ColumnNames(rename_table) } ), MissingField.Ignore )Where #"Reordered Columns" is the table result of the M-Code step before, looking like this:
While ProjectLables_indexed returns this table:respectively rename_table returns:
I know, rename_table isn´t in the form as required, but transformations as this
or
on rename_table gave the same error message at #"Rename_Columns".
Maybe I should use a totally different method to replace columns 1 to 6 names of #"Reordered Columns" by the rows 1 to 6 values of column [DOW - ProjectLabel] in table ProjectLables_indexed , but I´ve no idea yet how to do it.Many thanks in advance for your support.
Regards,
StefanEDIT:
Using hard coded pairs of renaiming, everything works fine:
#"Rename_Columns" = Table.RenameColumns(#"Reordered Columns", {{"1", "C300016"}, {"2", "CLIENT"}, {"3", "CON"}}, MissingField.Ignore ),Using List-Zip
myListZip = List.Zip( { Table.ColumnNames(#"Reordered Columns"), Table.ColumnNames(#"Promoted Headers") } ),
returns what I think was intended to be returned inside Imke´s code:
However, combining this into
#"Rename_Columns" = Table.RenameColumns(#"Reordered Columns", myListZip, MissingField.Ignore )
still returns Expression.Error: We expected a RenameOperations value.
- ChemEnger3 years agoAdvocate V
An old thread but a good one. Anonymous, I've just been scratching my head with exactly this issue - we don't seem to be able to rename a column with an integer (or other numerical) type in the Index column, as created with a Table.AddIndexColumn command.
The Index column needs transforming to text in a separate command* and everything should work OK.
*note that just specifying type text as the index is created is not sufficient!
- vancromy8 years agoFrequent Visitor
Thanks both! That's done the trick and I've learnt about a new PQ function in the process :)
- Luthiendsa7 years agoNew Member
Hi ImkeF,
Where do I put the " #"Rename Columns" = Table.RenameColumns(Table2, List.Zip( { Table.ColumnNames(Table2), Table.ColumnNames(Table1) } ) ) "?
I am a beginner in Power BI and I really could use the solution you gave.
- ImkeF7 years agoCommunity Champion
Hi , Luthiendsa ,
did you check the link from my signature already?: http://community.powerbi.com/t5/Webinars-and-Video-Gallery/Power-BI-Forum-Help-How-to-integrate-M-code-into-your-existing/m-p/179314
Please let me if that makes sense or you need further advise.
- thebestPBI3 years agoFrequent Visitor
The solution working fine, thank you for sharing