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

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

Reply
Anonymous
Not applicable

Replacing a word in every list of a single column

I have a column in my table where every cell consists of one list of words. I want to replace certain word with another one from each of these lists but I am not sure how to do that. I have tried similar M language scripts as I do in the case where a column consists of text, but now I get only error messages. 

 

Example:

Column 1
{"Cat", "Dog", "Mouse"}
{"Cat, Dog"}
{"Dog"}
{"Dog", "Tiny Mouse"}

 

So the "elements" in this column are lists. Say I want to change all "Mouse" words to "Rat". The desired result would be:

 

Column 1
{"Cat", "Dog", "Rat"}
{"Cat, "Dog"}
{"Dog"}
{"Dog", "Tiny Rat"}
1 ACCEPTED SOLUTION

Use this

= Table.ReplaceValue(Custom1, each [Column 1], each List.Transform([Column 1],(x)=>Text.Replace(x,"Mouse","Rat")), Replacer.ReplaceValue,{"Column 1"})

View solution in original post

5 REPLIES 5
Vijay_A_Verma
Super User
Super User

Can you please post some sample data from table and also list of replacement words?

Anonymous
Not applicable

Hi, I added an example to my original message. 

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

Important for you is the last Table.ReplaceValue.

I have used first Table.ReplaceValue for converting your example values into a list.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wqo5Rck4siVHSUYhRcslPhzB880uLU2OUapVidbCogAtj4aHqjgUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Column 1" = _t]),
    Custom1 = Table.ReplaceValue(Source, each [Column 1], each Expression.Evaluate([Column 1]),Replacer.ReplaceValue,{"Column 1"}),
    Custom2 = Table.ReplaceValue(Custom1, each [Column 1], each List.ReplaceMatchingItems([Column 1],{{"Mouse","Rat"}}), Replacer.ReplaceValue,{"Column 1"})
in
    Custom2

 

Anonymous
Not applicable

Thank you! I used the Table.ReplaceValue line and got it to work. Further, would it be possible to replace some part of a word as well?

 

For example, if one of those lists included a word "Tiny Mouse" and I wanted it to be replaced with "Tiny Rat" as well? 

Use this

= Table.ReplaceValue(Custom1, each [Column 1], each List.Transform([Column 1],(x)=>Text.Replace(x,"Mouse","Rat")), Replacer.ReplaceValue,{"Column 1"})

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.

Top Kudoed Authors