Forum Discussion

BZimber's avatar
BZimber
New Member
2 years ago
Solved

Power Query Replace using Wildcards ie Replace in Excel <*> with space

I find plenty of posts on how to replace things in a certain way but not what I need to do. I have a column that is an extract from devops which, when I bring it into Excel, it has all the html comma...
  • AlienSx's avatar
    AlienSx
    1 year ago

    this 

    let
        fx = (txt) => Text.Combine(
            List.Alternate(
                List.Select(Text.SplitAny(txt, "<>"), (x) => x <> ""), 
                1, 
                1, 
                Number.From(not Text.StartsWith(txt, "<"))
            ),
            " "
        ),
        Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content], 
        result = Table.TransformColumns(Source, {"Column1", fx})
    in
        result

    replaces <, > and everything in between with space. If you don't need space - simply remove " " in Text.Combine call.  

  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi,

    Thanks for the solutions everyone offered, and i want to offer some more information for user to refer to.

    hello BZimber , you can create a blank query, and put the following code to advanced editor in power query.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wiik1MDBOTsksAzNSE5OSISL6cKGU1DSlWB2YSoQ4mk5DI2MTUzO4oEJxSWVOqm2MUlJ+hW5xZlVmXrpVUn5RSmqRLlDEOgZiXKpSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let a=Text.Split([Column1],">"),
    b=List.Transform(a,each if Text.Contains(_,"<") then Text.BeforeDelimiter(_,"<") else _),
    c=Text.Combine(b," ")
    in c),
        #"Trimmed Text" = Table.TransformColumns(#"Added Custom",{{"Custom", Text.Trim, type text}})
    in
        #"Trimmed Text"

    Output

    Best Regards!

    Yolo Zhu

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