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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Petjak
New Member

Rename content of a column if a certain content in another column exists

A little tricky Subject Headline... Since im quite new to the Power BI game. I'd like to know if there is a way to rename contents of for example column "b" if a certain content in column "a" exists. Somehow i dont find a fitting solution with the Query Editor. 

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

Yes, Table.Replace value is used for this. An example below

=Table.ReplaceValue(#"Changed Type",each [b],each if [a] ="abc" then "x" else [b],Replacer.ReplaceValue,{"b"})

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKk8tUtJRKihQitWJVkpMSgZyCgvBnPKSysoSILeoCEmuuFgpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [a = _t, b = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"a", type text}, {"b", type text}}),
    Custom1 = Table.ReplaceValue(#"Changed Type",each [b],each if [a] ="abc" then "x" else [b],Replacer.ReplaceValue,{"b"})
in
    Custom1

View solution in original post

2 REPLIES 2
Vijay_A_Verma
Super User
Super User

Yes, Table.Replace value is used for this. An example below

=Table.ReplaceValue(#"Changed Type",each [b],each if [a] ="abc" then "x" else [b],Replacer.ReplaceValue,{"b"})

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKk8tUtJRKihQitWJVkpMSgZyCgvBnPKSysoSILeoCEmuuFgpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [a = _t, b = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"a", type text}, {"b", type text}}),
    Custom1 = Table.ReplaceValue(#"Changed Type",each [b],each if [a] ="abc" then "x" else [b],Replacer.ReplaceValue,{"b"})
in
    Custom1
ronrsnfld
Super User
Super User

You can do it but you have to get into the Advanced Editor.

This code provides an example of one way to do this:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxKVtJRMlSK1YlWSklNA7KNwOz0jEwg2xjMzsrOAbJNlGJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [a = _t, b = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"a", type text}, {"b", Int64.Type}}),

    #"Look for in col A" = "ghi",
    #"Conditional Rename" = if List.Contains(#"Changed Type"[a],#"Look for in col A") 
        then Table.RenameColumns(#"Changed Type",{"b","New Col Name"}) 
        else #"Changed Type"

in
    #"Conditional Rename"

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.