Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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

1 ACCEPTED SOLUTION

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

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-cherch-msft
Employee
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

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not 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?

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

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.