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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
allieg2830
New Member

How to add a column that indicates whether values in a column contain any of a list of keywords?

Hi!

 

My goal is to write a function that basically answers, If the title contains any of the following words, then Y

 

Specific example: the title is "Supergoop! Unseen Sunscreen SPF 40, Reef-Friendly Face Sunscreen for All Skin Types"

 

If the title contains any of the following words, I'd want the column value to be "Y" (yes). If not, then "N".

- reef safe, reef-friendly, reef friendly, reef-safe, coral reef

 

So, the value here would be "Y"

 

Any suggestions?? 

 

Thank you so much!

 

 

1 ACCEPTED SOLUTION
smpa01
Super User
Super User

@allieg2830  you can write a dynamic measure like this if you have two tables, one for the lookup value and one for the string, without needing to hardcode. Pbix is attached

 

The same expression doubles as a calculated column

 

Measure =
VAR _lookup =
    MAXX (
        FILTER (
            CROSSJOIN ( VALUES ( t1[Column1] ), VALUES ( t2[LookupValue] ) ),
            CONTAINSSTRING ( [Column1], [LookupValue] )
        ),
        [LookupValue]
    )
RETURN
    IF ( _lookup <> BLANK (), "Y", "N" )

 

smpa01_0-1639668042736.png

 

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

3 REPLIES 3
smpa01
Super User
Super User

@allieg2830  you can write a dynamic measure like this if you have two tables, one for the lookup value and one for the string, without needing to hardcode. Pbix is attached

 

The same expression doubles as a calculated column

 

Measure =
VAR _lookup =
    MAXX (
        FILTER (
            CROSSJOIN ( VALUES ( t1[Column1] ), VALUES ( t2[LookupValue] ) ),
            CONTAINSSTRING ( [Column1], [LookupValue] )
        ),
        [LookupValue]
    )
RETURN
    IF ( _lookup <> BLANK (), "Y", "N" )

 

smpa01_0-1639668042736.png

 

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

@allieg2830 Note that this checks the entire column t1[Column1] at once. If you only want to check for keywords one row at a time, then it can be simplified a bit.

Column1ContainsKeyword =
VAR _matchingKeywords =
    FILTER ( VALUES ( t2[keyword] ), CONTAINSSTRING ( t1[Column1], t2[keyword] ) )
RETURN
    IF ( ISEMPTY ( _matchingKeywords ), "N", "Y" )
Samarth_18
Community Champion
Community Champion

Hi @allieg2830 ,

You can create a column using below code:-

Column 2 =
SWITCH (
    TRUE (),
    CONTAINSSTRING ( Contains_specific_string[column], "reef-friendly" ), "Y",
    CONTAINSSTRING ( Contains_specific_string[column], "reef safe" ), "Y",
    CONTAINSSTRING ( Contains_specific_string[column], "reef friendly" ), "Y",
    CONTAINSSTRING ( Contains_specific_string[column], "reef-safe" ), "Y",
    CONTAINSSTRING ( Contains_specific_string[column], "coral reef" ), "Y",
    "N"
)

 

Thanks,

Samarth

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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