Forum Discussion
Wahid777
5 years agoFrequent Visitor
Creating a conditional column with boolean (Yes/No) result for matching partial text matches
Hi I've got a column listed as below and I'm trying to create a new column (with a Yes/No or True/False response) if some matches of certain keywords are found in the original column. Would "CONT...
- 5 years ago
Hi, Wahid777
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table1:
Table2:
You may create a custom column with the following codes.
if List.ContainsAny(Text.Split([Original column]," "),Table2[Keywords],Comparer.OrdinalIgnoreCase) then "Yes" else "No"Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Jimmy801
5 years agoCommunity Champion
Hello Wahid777
you can use a combination of List.Transform, List.AnyTrue and Text.Contains. Here the example
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Pc0xDsIwEETRq4xccwmEKAggihAEilwYZ1Fc2BvtusC3x7FE6vdHM47mKuh4TgiKPBMOxxv4g6+xu2qKS0mbPYInLEIaJkp5zV4tu3P8Jy6+naqbWFYe+j0yNxjOLe1IpGxfHBeXCnryQtlVqJsnTskba38=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Original column" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Original column", type text}}),
CheckWords = Table.AddColumn
(
#"Changed Type",
"Check",
(add)=> List.AnyTrue(List.Transform({"Ambassador","CEO","Chief Executive Officer","Chief Financial Officer","CFO"}, each Text.Contains(Text.Upper(add[Original column]), Text.Upper(_))))
)
in
CheckWords
Copy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy