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) } ) )
You were pretty close already:
#"Rename Columns" = Table.RenameColumns(Table2, List.Zip( { Table.ColumnNames(Table2), Table.ColumnNames(Table1) } ) )
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,
Stefan
EDIT:
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!