Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin 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.
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!
Solved! Go to Solution.
@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" )
@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" )
@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" )
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
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
11 | |
9 | |
8 | |
8 | |
7 |
User | Count |
---|---|
14 | |
12 | |
11 | |
10 | |
9 |