Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
chadnelson
Helper I
Helper I

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?

1 ACCEPTED SOLUTION

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

https://1drv.ms/u/s!AiUZ0Ws7G26RixzOI0gpuWV6jNLW?e=gWIFbE

View solution in original post

11 REPLIES 11
Ashish_Mathur
Super User
Super User

Hi,

Share some data to work with and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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)

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]),"(")

Screenshot_3.png

Unfortunately that didn't work. It returned the following error:

 

"Expression.Error: There is an unknown identifier. Did you use the [field] shorthand for a _[field] outside of an 'each' expression?"

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

https://1drv.ms/u/s!AiUZ0Ws7G26RixzOI0gpuWV6jNLW?e=gWIFbE

This worked! Thank you, so much.

 

= Table.AddColumn(#"Changed Type", "Custom", each Text.Combine(
List.Transform(
Text.Split([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.ReplaceRange(x,t1,1,",") else x ][repl]),"("))

or this code

Text.Combine(
List.Transform(
    Text.Split([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]),"(")

sorry this code corrected

Text.Combine(
List.Transform(
    Text.Split([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.ReplaceRange(x,t1,1,",") else x ][repl]),"(")

It is still giving me the same expression error.

Ahmedx
Super User
Super User

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

Screenshot_2.png

show an example so we can help you

speedramps
Super User
Super User

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

speedramps_0-1697231631301.png

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.