Forum Discussion

RE's avatar
RE
Icon for Helper I rankHelper I
9 years ago
Solved

M if text contains

I'm fairly new to M and I'm not sure if this functionality is even avaliable but what I'm trying to do is replace text that contians a specific word. For example, In my data set I have the same compa...
  • v-yulgu-msft's avatar
    9 years ago

    Hi RE,

     

    Here are two options for your reference

     

    1. add a conditional column

     

    Corresponding M query:

    = Table.AddColumn(#"PreviousStep", "Custom", each if Text.Contains([Column1], "Coca") then "Coca Cola" else [Column1] )

    2. Replace values on original column directly.

    #"Replaced Value" = Table.ReplaceValue( #"PreviousStep" ,each [Column1],each if Text.Contains([Column1], "Coca") then "Coca Cola" else [Column1],Replacer.ReplaceValue,{"Column1"})
    

    Best regards,
    Yuliana Gu