Forum Discussion

cristianml's avatar
cristianml
Post Prodigy
4 years ago
Solved

Multiple strings table.replacevalue

Hi,

I need help to use in M (query editor) the replacevalue function for multiple strings. This is what I have so far:

 

Table.ReplaceValue(Source,each [COLUMN1], each if(
{"String1","StringReplaced1"}
{"String2","StringReplaced2"}
{"String3","StringReplaced3"}
{"String4","StringReplaced4"}
{"String5","StringReplaced5"}
{"String6","StringReplaced6"}
{"String7","StringReplaced7"}
{"String8","StringReplaced8"}
{"String9","StringReplaced9"}
{"String10","StringReplaced10"}
{"String11","StringReplaced11"}
{"String12","StringReplaced12"}
{"String13","StringReplaced13"}
{"String14","StringReplaced14"}
else "N/A") 

 

 

The idea is to replace from a a specific column different strings/text.

 

Example replace "String1" with "StringReplaced1" and so on ..

 

Hope you can help me.

 

Thanks.

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi cristianml ,

    Please have a try.

    Table.ReplaceValue(#"Changed Type", each [COLUMN], 
    each if Text.Contains([COLUMN], "String1") then Text.Replace([Custom], "String1", "StringReplaced1")
    else if Text.Contains([COLUMN], "String2") then Text.Replace([Custom], "String2", "StringReplaced2")
    else if Text.Contains([COLUMN], "String3") then Text.Replace([Custom], "String3", "StringReplaced3")
    else if Text.Contains([COLUMN], "String4") then Text.Replace([Custom], "String4", "StringReplaced4")
    else if Text.Contains([COLUMN], "String5") then Text.Replace([Custom], "String5", "StringReplaced5")
    else if Text.Contains([COLUMN], "String6") then Text.Replace([Custom], "String6", "StringReplaced6")
    else if Text.Contains([COLUMN], "String7") then Text.Replace([Custom], "String7", "StringReplaced7")
    else if Text.Contains([COLUMN], "String8") then Text.Replace([Custom], "String8", "StringReplaced8")
    else if Text.Contains([COLUMN], "String9") then Text.Replace([Custom], "String9", "StringReplaced9")
    else if Text.Contains([COLUMN], "String10") then Text.Replace([Custom], "String10", "StringReplaced10")
    else if Text.Contains([COLUMN1], "String11") then Text.Replace([Custom], "String11", "StringReplaced11")
    else if Text.Contains([COLUMN], "String12") then Text.Replace([Custom], "String12", "StringReplaced12")
    else if Text.Contains([COLUMN], "String13") then Text.Replace([Custom], "String13", "StringReplaced13")
    else if Text.Contains([COLUMN], "String14") then Text.Replace([Custom], "String14", "StringReplaced14")
    else "NA", Replacer.ReplaceText,{"COLUMN"})

     

    If I have misunderstood your meaning, please provide more details with your desired output and your pbix file without privacy information.

     

    Best Regards

    Community Support Team _ Polly

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

     

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi cristianml ,

    Please have a try.

    Table.ReplaceValue(#"Changed Type", each [COLUMN], 
    each if Text.Contains([COLUMN], "String1") then Text.Replace([Custom], "String1", "StringReplaced1")
    else if Text.Contains([COLUMN], "String2") then Text.Replace([Custom], "String2", "StringReplaced2")
    else if Text.Contains([COLUMN], "String3") then Text.Replace([Custom], "String3", "StringReplaced3")
    else if Text.Contains([COLUMN], "String4") then Text.Replace([Custom], "String4", "StringReplaced4")
    else if Text.Contains([COLUMN], "String5") then Text.Replace([Custom], "String5", "StringReplaced5")
    else if Text.Contains([COLUMN], "String6") then Text.Replace([Custom], "String6", "StringReplaced6")
    else if Text.Contains([COLUMN], "String7") then Text.Replace([Custom], "String7", "StringReplaced7")
    else if Text.Contains([COLUMN], "String8") then Text.Replace([Custom], "String8", "StringReplaced8")
    else if Text.Contains([COLUMN], "String9") then Text.Replace([Custom], "String9", "StringReplaced9")
    else if Text.Contains([COLUMN], "String10") then Text.Replace([Custom], "String10", "StringReplaced10")
    else if Text.Contains([COLUMN1], "String11") then Text.Replace([Custom], "String11", "StringReplaced11")
    else if Text.Contains([COLUMN], "String12") then Text.Replace([Custom], "String12", "StringReplaced12")
    else if Text.Contains([COLUMN], "String13") then Text.Replace([Custom], "String13", "StringReplaced13")
    else if Text.Contains([COLUMN], "String14") then Text.Replace([Custom], "String14", "StringReplaced14")
    else "NA", Replacer.ReplaceText,{"COLUMN"})

     

    If I have misunderstood your meaning, please provide more details with your desired output and your pbix file without privacy information.

     

    Best Regards

    Community Support Team _ Polly

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.