Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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
User | Count |
---|---|
22 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
25 | |
13 | |
11 | |
9 | |
6 |