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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Dom87326
Helper II
Helper II

Bulk replace text values in single step

Hello, 

 

I'm trying to replace multiple text values in one power query step. In the example below, New York and Los Angeles should be changed to Boston.

 

Dom87326_0-1652189973358.png

 

Any help appreciated. 

 

Thanks!

2 ACCEPTED SOLUTIONS
Vijay_A_Verma
Super User
Super User

In a Custom column put following

= if List.Contains({"New York","Los Angeles"},[Column A]) then "Boston" else [Column A]

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("i45W8kstV4jML8pWitWJVnLKLy7JzwMzffKLFRzz0lNzUovBfI/8Uricb2ZibqZSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Column A" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Column B", each if List.Contains({"New York","Los Angeles"},[Column A]) then "Boston" else [Column A])
in
    #"Added Custom"

View solution in original post

For same column, insert this step where Source should be replaced with your previous step

= Table.ReplaceValue(Source,each [Column A],each if List.Contains({"New York","Los Angeles"},[Column A]) then "Boston" else [Column A],Replacer.ReplaceValue,{"Column A"})

View solution in original post

3 REPLIES 3
Dom87326
Helper II
Helper II

@Vijay_A_Verma could you please advise how to use it in the same column? 

For same column, insert this step where Source should be replaced with your previous step

= Table.ReplaceValue(Source,each [Column A],each if List.Contains({"New York","Los Angeles"},[Column A]) then "Boston" else [Column A],Replacer.ReplaceValue,{"Column A"})
Vijay_A_Verma
Super User
Super User

In a Custom column put following

= if List.Contains({"New York","Los Angeles"},[Column A]) then "Boston" else [Column A]

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("i45W8kstV4jML8pWitWJVnLKLy7JzwMzffKLFRzz0lNzUovBfI/8Uricb2ZibqZSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Column A" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Column B", each if List.Contains({"New York","Los Angeles"},[Column A]) then "Boston" else [Column A])
in
    #"Added Custom"

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Top Solution Authors