Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Replace Value in Text String if Match

Hello,   I have a question regarding dax syntax in power query using data similiar to the sample data found below:   Input Color   Input Values   Output blue   ten, blue, vegetable, m...
  • v-yueyunzh-msft's avatar
    3 years ago

    HI , Anonymous 

    According to your description, you want to Replace Value in Text String if Match.Thanks for your sample data and your sample data the splite text is ", ".

    Here are the steps you can refer to :
    (1)My test data is the same as yours.

    (2)You can create a blank query in Power Query Editor and create a "Advanced Editor":

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("LY3BCsMwDEN/JeTsPwo5uKvWhnoxuG7D/n5u2EkCPUml5EUuZMqOTunxlG5scF4k7KfJce58IFcqeTOgBzuVkvamIT4gd7AOnpRhDebFZuonpcEOi3Rv5rPmxq1P8gsRHc95DMZ7s5XSW6/A/1GtPw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Input Color" = _t, #"Input Values" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Input Color", type text}, {"Input Values", type text}}),
        Custom1 = Table.TransformColumns(#"Changed Type",{"Input Values",(x)=>  Text.Split(x,", ")   }),
        #"Added Custom" = Table.AddColumn(Custom1, "Output", (x)=>   List.Difference( x[Input Values] ,{x[Input Color]}    )     ),
        #"Removed Columns" = Table.TransformColumns(Table.RemoveColumns(#"Added Custom",{"Input Values"}), {"Output",(x)=>Text.Combine(x,", ")     }  )
    in
        #"Removed Columns"

     

    Then wen can get the result as follows:

     

     

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

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