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
martindoll
Frequent Visitor

Replacing Text within each cell of a column

I have been trying to get something to work all day.  In Transforming data in Power QUery, I need to replace vlaues.

Example:

Column1 has a combination of 85 possible values.

I need to go through each row of the column and Replace the value of each cell.

If I create 85 Replace Values, it exceeds the query limit.

I have tried about a dozen different scenarios I have searched for....none of them work for me.

Sample of the data

Column1

100000001, 100000002

100000001

100000001,100000002,100000003

 

I want

100000001 = Blue

100000002 = Red

100000003 = Yellow

 

So when it is done, it looks like:

Column1

Blue, Red

Blue

Blue, Red, Yellow

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @martindoll ,

Combines both of the above methods:

vcgaomsft_0-1728023348197.png

let
    ToRows = Table.ToRows( Parameter ),
    Outcome =
        List.Accumulate(
            ToRows,
            SourceTable,
            (x, y) =>
                Table.ReplaceValue(
                    x,
                    y{0},
                    y{1},
                    Replacer.ReplaceText,
                    {"Column1"}
                )
        )
in
    Outcome

vcgaomsft_3-1728023401279.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum 

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @martindoll ,

Combines both of the above methods:

vcgaomsft_0-1728023348197.png

let
    ToRows = Table.ToRows( Parameter ),
    Outcome =
        List.Accumulate(
            ToRows,
            SourceTable,
            (x, y) =>
                Table.ReplaceValue(
                    x,
                    y{0},
                    y{1},
                    Replacer.ReplaceText,
                    {"Column1"}
                )
        )
in
    Outcome

vcgaomsft_3-1728023401279.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum 

Omid_Motamedise
Super User
Super User

You can solve this problem in several ways, whihc using List.Accumulate for running over the replaces pairs can be helpfull as follow.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjSAAEMdBRjTSClWB0kClacDVwVnGSvFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    Replace = Table.TransformColumns(Source,{{"Column1", each List.Accumulate({{"100000001","Blue"},{"100000002","Red"},{"100000003","Yellow"}},_,(a,b)=>Text.Replace(a,b{0},b{1})), type text}})
in
    Replace

 which results in 

Omid_Motamedise_0-1727999854391.png




If you need to know more about this function jucst see my video here

https://www.youtube.com/watch?v=G8PRbWuDcmQ


If my answer helped solve your issue, please consider marking it as the accepted solution.
Ahmedx
Super User
Super User

pls try this

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjSAAEMdBRjTSClWB0kClacDVwVnGSvFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
 dict = List.Buffer( Table.ToList(DimColor,(x)=>x)),
 f = (x)=> Text.Combine( List.Transform( Text.Split(x,","), (x)=> List.Skip(dict,(y)=>not Text.Contains(x,y{0})){0}?{1}?),","),
 to = Table.TransformColumns(Source,{"Column1",f})
in
to

Screenshot_1.png

lbendlin
Super User
Super User

lbendlin_0-1727996996859.png

 

Note that this will fail if there isn't a color for a certain data item.

 

Data:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjSAAEMdBRjTSClWB0kClacDVwVnGSvFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Added Index", {{"Column1", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Column1"),
    #"Trimmed Text" = Table.TransformColumns(#"Split Column by Delimiter",{{"Column1", Text.Trim, type text}}),
    #"Added Custom" = Table.AddColumn(#"Trimmed Text", "Color", (k)=> Table.SelectRows(Replace, each [Value]=k[Column1])[Color]?{0}?,type text),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"Index"}, {{"Column1", each Text.Combine([Color],", "), type text}})
in
    #"Grouped Rows"

 

 

Replace:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjSAAEMlHSWnnNJUpVgdhKARUDAoNQVFzBgoFpmak5NfrhQbCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Value = _t, Color = _t])
in
    Source

 

You may also need to wrap the Replace table in a Table.Buffer.

 

Thanks for all the replies.....I needed to use the first suggestion because the parameters change and I needed it easy for end users to update....thanks to everyone.

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.