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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request 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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.