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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ShajiFiroz
New Member

extract specific text from Colum

I need to extract specific text from a column and output the result in a conditional column.
For example, I need to extract the word "Marketing"  from the following sentence in the column, "This is for Marketing team to take action". Then, output "Marketing" in the newly created conditional column. 

 

Looking forward to hearing from experts. Thank you

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @ShajiFiroz 

Please download my sample PBIX with this data and code.

It's not clear if you are looking for only a single string "Marketing" or if you want to look for several different strings.  Always best if you supply some sample data.

If you are looking for several strings you can create a Calculated Column like so

Column = SWITCH (

    TRUE(),
    
    CONTAINSSTRING ( 'Table'[TextCol], "Marketing" ), "Marketing",

    CONTAINSSTRING ( 'Table'[TextCol], "Sales" ), "Sales", 

    CONTAINSSTRING ( 'Table'[TextCol], "HR" ), "HR", 

    CONTAINSSTRING ( 'Table'[TextCol], "Technology" ), "Technology", 

    CONTAINSSTRING ( 'Table'[TextCol], "Finance" ), "Finance", 

    ""
)

resulting in this

text-col.png

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

5 REPLIES 5
PhilipTreacy
Super User
Super User

Hi @ShajiFiroz 

Please download my sample PBIX with this data and code.

It's not clear if you are looking for only a single string "Marketing" or if you want to look for several different strings.  Always best if you supply some sample data.

If you are looking for several strings you can create a Calculated Column like so

Column = SWITCH (

    TRUE(),
    
    CONTAINSSTRING ( 'Table'[TextCol], "Marketing" ), "Marketing",

    CONTAINSSTRING ( 'Table'[TextCol], "Sales" ), "Sales", 

    CONTAINSSTRING ( 'Table'[TextCol], "HR" ), "HR", 

    CONTAINSSTRING ( 'Table'[TextCol], "Technology" ), "Technology", 

    CONTAINSSTRING ( 'Table'[TextCol], "Finance" ), "Finance", 

    ""
)

resulting in this

text-col.png

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


@PhilipTreacy this worked, awesome 🙂 

Anonymous
Not applicable

You can also use the CONTAINSSTRING command in Dax, for example, 

 

Column =
IF (
    CONTAINSSTRING ( 'Table'[Column1], "Marketing" ),"Marketing",
    IF ( CONTAINSSTRING ( 'Table'[Column1], "Test" ), "Test", 
    "Null" )
)

 

 

 

Karlos_2-1611571207607.png

 

 

 

Thanks @Anonymous 

Anonymous
Not applicable

Power Query, Conditional column

Karlos_0-1611567280471.png

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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