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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Anonymous
Not applicable

Custom Column to extract STRING

Hi Experts

 

How would you extract all data from column Work Type that has in the string of text the letter ABC and or BCD anywhere in the string...into a new column and all other entries are blank in the new column.. so see example below....

 

see imageCapture.PNG

1 ACCEPTED SOLUTION
Stachu
Community Champion
Community Champion

try this PowerQuery code, apply it in Add Column>Custom Column window

[
abc = Text.PositionOf([Work Type],"ABC"),
bcd = Text.PositionOf([Work Type],"BCD"),
resultABC = if abc <> -1 then Text.Middle([Work Type],abc,3) else null,
resultBCD = if bcd <> -1 then Text.Middle([Work Type],bcd,3) else null,
result = Text.Combine({resultABC, resultBCD})
][result]


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

View solution in original post

3 REPLIES 3
Stachu
Community Champion
Community Champion

try this PowerQuery code, apply it in Add Column>Custom Column window

[
abc = Text.PositionOf([Work Type],"ABC"),
bcd = Text.PositionOf([Work Type],"BCD"),
resultABC = if abc <> -1 then Text.Middle([Work Type],abc,3) else null,
resultBCD = if bcd <> -1 then Text.Middle([Work Type],bcd,3) else null,
result = Text.Combine({resultABC, resultBCD})
][result]


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Is there a way to extract a substring where I do not know the length? I know the pattern of the start but I do not know when the string I am expecting terminates. If I have to run a python script, how would I do it?

Anonymous
Not applicable

Stachu...Excellent feedback....and happy to learn also....thank you

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors