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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Nipius
Advocate I
Advocate I

Remove text between characters

Hi!

 

I have a column in a Power BI query with names. In case of absence of a person, the system adds (On Leave) to the name of the employee. So, if John Doe is absent for 2 months, the report shows John Doe (On Leave).

 

Also, in some cases, the system provides an output where the name of the person is added in a different writing. Particularly, in Asian countries, the system adds the name of the person in the original writing.

 

In both case, I'd like to have everything between brackets (including the brackets) removed. Is there a solution to this? 

 

Thanks so much in advance for your support!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Nipius ,

 

I hop[e you have access to edit queries.

if so these are the steps:

 

1-  Data looks like this

step 1.PNG

 

2- right click and hit on split column , you will get output like this. Hit ok

step 2.PNG

 

3. remove the column which was created after splitting.

step 3.PNG

 

4. Output looks like this

 

step 4.PNG

 

 

Let me know if this works.

 

Thanks,

Tejaswi

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

There is an even simpler solution.

You can create a new function called fun_ReplaceTextBetweenDelimiters, and in it add this code 👇

let
    fun_ReplaceTextBetweenDelimiters = (Text as text, StartDelimiter as text, EndDelimiter as text, optional ReplaceDelimiters as nullable logical, optional NewText as nullable text, optional TrimResult as nullable logical, optional FixDoubleSpaces as nullable logical) as text => 
        let
            // Add Default Parameters
            Default_ReplaceDelimiters = if ReplaceDelimiters is null then true else ReplaceDelimiters,
            Default_NewText = if NewText is null then "" else NewText,
            Default_TrimResult = if TrimResult is null then true else TrimResult,
            Default_FixDoubleSpaces = if FixDoubleSpaces is null then true else FixDoubleSpaces,
            //Do work
            TextBetweenDelimiters = Text.BetweenDelimiters(Text, StartDelimiter, EndDelimiter),
            TextToReplace = if Default_ReplaceDelimiters then Text.Combine({StartDelimiter,TextBetweenDelimiters,EndDelimiter}) else TextBetweenDelimiters,
            ReplacedText = Text.Replace(Text, TextToReplace, Default_NewText),
            //Clean Result
            TrimmedText = if Default_TrimResult then Text.Trim(ReplacedText) else ReplacedText,
            FixedSpaces = if Default_FixDoubleSpaces then Text.Replace(TrimmedText, "  ", " ") else TrimmedText
        in
            FixedSpaces
in
    fun_ReplaceTextBetweenDelimiters

Then, we can test it like this:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyVtAw1FTSAbGUYnWilVzd3BU0jEAiQBZYJCIyCqhGRwEsCOQoxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [TestData = _t, TargetData = _t]),
    ChangeType = Table.TransformColumnTypes(Source,{{"TestData", type text}, {"TargetData", type text}}),
    RunFunction = Table.AddColumn(ChangeType, "NewText", each fun_ReplaceTextBetweenDelimiters([TestData], "(", ")", true), type text),
    TestResult = Table.AddColumn(RunFunction, "Test", each [TargetData]=[NewText], type logical)
in
    TestResult

Input:

TestData TargetData
ABC (1)ABC
EFG (2)EFG
XYZ (1, 2)XYZ

Output:

TestData TargetData NewText Test
ABC (1)ABCABCTRUE
EFG (2)EFGEFGTRUE
XYZ (1, 2)XYZXYZTRUE
Anonymous
Not applicable

Hi @Nipius ,

 

A little confuse with your requirments.

 

Do you want the output to look like this? or do you want to remove (on leave) in your report?

 

Capture 120.PNG

@Anonymous Thanks for the response!

 

So, originally the data looks like this "Name (On Leave)" or "Name (Name in different writing)". I want everything to look like "Name". So for all the records where there is data between brackets in the records, I'd like to remove this part.

Anonymous
Not applicable

Hi @Nipius ,

 

I hop[e you have access to edit queries.

if so these are the steps:

 

1-  Data looks like this

step 1.PNG

 

2- right click and hit on split column , you will get output like this. Hit ok

step 2.PNG

 

3. remove the column which was created after splitting.

step 3.PNG

 

4. Output looks like this

 

step 4.PNG

 

 

Let me know if this works.

 

Thanks,

Tejaswi

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors