Forum Discussion
Auto-renaming columns based on value in another COLUMN
Hi, everyone!
I am trying to rename Field A based on a Value in Field B using M. For example
Field A Field B
1 "Field C"
2 "Field C"
3 "Field C"
Automatically renames to the following
Field C Field B
1 "Field C"
2 "Field C"
3 "Field C"
I tried the following:
#"Renamed Columns" = Table.RenameColumns(#"Added Custom",{{"Custom", [Field B]{0}}})
However, it returned the following error:
"Expression.Error: There is an unknown identifier. Did you use the [field] shorthand for a _[field] outside of an 'each' expression?"
Any help would be most appreciated! Scott
Hi Anonymous
Yes. You may have a look at my sample file here.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJWitWJVjKCs4whrFgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [A = _t, B = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"A", Int64.Type}, {"B", type text}}), #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"A", #"Changed Type"[B]{0}}}) in #"Renamed Columns"Regards,
Cherie
3 Replies
- v-cherch-msft
Microsoft Employee
Hi Anonymous
You may refer to below post. Show a sample as below:
https://community.powerbi.com/t5/Desktop/Dynamic-column-name-from-its-value/td-p/189442
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJWitWJVjKCs4whrFgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [A = _t, B = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"A", Int64.Type}, {"B", type text}}), #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"A", #"Changed Type"[B]{0}}}) in #"Renamed Columns"Regards,
Cherie
- AnonymousNot applicable
Thanks for the help, but I do not think that is what I was looking for. That tells me how to rename a field based on a value in its own column. I am wondering if I can rename a field based on a value in a different column. Can I do so with the same design?
- v-cherch-msft
Microsoft Employee
Hi Anonymous
Yes. You may have a look at my sample file here.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJWitWJVjKCs4whrFgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [A = _t, B = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"A", Int64.Type}, {"B", type text}}), #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"A", #"Changed Type"[B]{0}}}) in #"Renamed Columns"Regards,
Cherie