cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
ELW Frequent Visitor
Frequent Visitor

Remove strings within parentheses from Power Query Editor

Is there a way to remove various strings from within parentheses from the query editor in PowerBI?  There could be 0, 1, or multiple instances of text within parenthesis I need to remove from my strings.  I need to do it within the query.  I've tried using ReplaceValue with an asterisk, but that doesn't seem like it works this way.  

 

Here's a gibberish example: 

 

BEFOREAFTER
Lorem ipsum (ABC) dolor sit ametLorem ipsum dolor sit amet
consectetur adipiscing elit (DE)consectetur adipiscing elit
sed do (FGHI) eiusmod tempor incididuntsed do eiusmod tempor incididunt
ut labore et dolore (JKLM) magna aliqua (NOP)ut labore et dolore magna aliqua
Ut enim ad minim veniamUt enim ad minim veniam

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Remove strings within parentheses from Power Query Editor

@ELW ,

 

An simple way than power query is to write a python script to replace (...) using non-greedy matching.

# 'dataset' holds the input data for this script

import pandas as pd

dataset["AFTER"] = dataset.replace(to_replace=r'\(.*?\)', value='', regex=True)

1.PNG2.PNG 

 

Community Support Team _ Jimmy Tao

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

View solution in original post

3 REPLIES 3
Super User
Super User

Re: Remove strings within parentheses from Power Query Editor

@ELW add new custom column in power query with following expression

 

Text.Replace(Text.Replace([BEFORE],"(",""), ")", "" )





Did I answer your question? Mark my post as a solution.

Proud to be a Datanaut! Appreciate your Kudos Smiley Happy
Feel free to email me with any of your BI needs.





ELW Frequent Visitor
Frequent Visitor

Re: Remove strings within parentheses from Power Query Editor

Thanks @parry2k!  I believe that just replaces the parentheses themselves while leaving the text inside them.  Is there a way to modify that formula to remove the text from inside the parentheses as well? 

Community Support Team
Community Support Team

Re: Remove strings within parentheses from Power Query Editor

@ELW ,

 

An simple way than power query is to write a python script to replace (...) using non-greedy matching.

# 'dataset' holds the input data for this script

import pandas as pd

dataset["AFTER"] = dataset.replace(to_replace=r'\(.*?\)', value='', regex=True)

1.PNG2.PNG 

 

Community Support Team _ Jimmy Tao

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

View solution in original post

Helpful resources

Announcements
Can You Solve These Challenge

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

Community News & Announcements

Community News & Announcements

Get your latest community news and announcements.

Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Users Online
Currently online: 217 members 2,211 guests
Please welcome our newest community members: