(Power Query) Remove text from second set of brackets onwards

Reiper79

New Member
Joined
Jun 15, 2021
Messages
21
Office Version
  1. 365
Platform
  1. Windows
Hi All. Can someone please help me out?

If I have a column where most of the rows contain text that looks something like "john (jack) smith (transport)", how do I remove the text from the end of "smith" onwards?

Also, some of my rows have text that look like "anthony (tony) smith". How do I do the above without affecting the text strings without the second set of brackets?

I've attached a bit of a sample of what I need things to look.

Thanks.
 

Attachments

  • Screenshot 2024-05-23 135953.jpg
    Screenshot 2024-05-23 135953.jpg
    42 KB · Views: 37

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Power Query:
let
    test = #table(type table [test = text], {{"john (jack) smith (transport)"}, {"john (jack) smith"}}),
    tx = Table.AddColumn(
        test, 
        "transformed", 
        (x) => if Text.EndsWith(x[test], ")") 
            then Splitter.SplitTextByEachDelimiter({" ("}, QuoteStyle.None, true)(x[test]){0} 
            else x[test]
    )
in
    tx
 
Upvote 0
Or:

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    result = Table.TransformColumns(Source,{{"Description", each  if Text.End(_,1) =")" then Text.BeforeDelimiter(_,"(",{0,RelativePosition.FromEnd}) else _}})
in
    result
 
Upvote 0
Sorry, I just realised I've probably led you astray. I should have said that one of my queries in Power Query has a column with rows that contain text that looks something like "john (jack) smith (transport)".

Can you please revise your solutions?

Greatly appreciated.
 
Upvote 0
So what is wrong with that? It should work for that string. Can you provide sample data with expected results? Instead of a picture
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top