Forum Discussion

chadnelson's avatar
chadnelson
Helper I
2 years ago
Solved

Remove semi colon only when inside parentheses

I have data that contains multiple values within a single cell. I am attempting to separate this data, but occasionally there are additional semi colons throughout these values that are not delimiters. I would like to replace all semi colons with commas, ONLY when the semi colon is inside parentheses. Any suggestions?

11 Replies

  • In Power query replace ";" with ,

    See screen print
    I am an unpaid volunteer helper seeking kudos.

    Please show your thanks by clicking the Accept Solution button and the thumbs up button to leave kudos.
    Thanks

     

  • if there is only a semicolon inside the parentheses then it is simple.

    show an example so we can help you

    • chadnelson's avatar
      chadnelson
      Helper I

      Thanks for the response and apologizes for not being clear in my initial post. The entire column contains cells similar to this:

       

      Person A (Company XYZ); Person B (Company 123); Person C (Company A-1; Accounting); Person D (Company B12)

       

      I would like to replace the instances where the semi-colon is inside the parentheses with a comma, to look like this.

       

      Person A (Company XYZ); Person B (Company 123); Person C (Company A-1, Accounting); Person D (Company B12)

      • Ahmedx's avatar
        Ahmedx
        Super User

        pls try this

        = Text.Combine(
        List.Transform(
        Splitter.SplitTextByAnyDelimiter({"("})([Column 1]),
        (x)=> [
            t1 = Text.PositionOf( x,";",Occurrence.First),
            t2 = Text.PositionOf( x,")",Occurrence.First),
            repl = if t1 < t2 and t1<> -1 and  t2<> -1 then Text.Replace(x,Text.Range(x,t1,1),",") else x ][repl]),"(")