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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

Check whether a string contains a value from another table

I have as a list (about 900) of values that I am interested in:
Genus Table:

Genus of interest
Metopina
Neuroptera
Corynoptera

In a separate table, I have free text (lab results). This is a very large dataset. 

I want to search the free text to see if they have any value in the genus table, and return a new column with Yes/No (or True/False, whatever.) 
Lab results table:

freetextExpected result
Colletotrichum sp. Disease symptomsNo
Corynoptera sp small flyYes
Indet. IDNo
Megaselia sp not knownNo
Metopina sp Diptera flyYes
Neuroptera A. Lacewing eggsYes
 


I tried modifying the solution from this post but it is returning an error for me:

 

= Table.AddColumn(#"Inserted Merged Column", "Genus", each List.First(List.Select(Genus Table, (x) => Text.Contains([freetext], x))))

 


I can write DAX pretty well but I don't know M at all so I've probably just mucked it up, but would appreciate some help 🙂

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Added Custom" = Table.AddColumn(Source, "Custom", each List.Contains(Genus[Genus of interest],[freetext],(x as text, y as text)=>Text.Contains(y,x,Comparer.OrdinalIgnoreCase)))
in
    #"Added Custom"

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Added Custom" = Table.AddColumn(Source, "Custom", each List.Contains(Genus[Genus of interest],[freetext],(x as text, y as text)=>Text.Contains(y,x,Comparer.OrdinalIgnoreCase)))
in
    #"Added Custom"

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
danextian
Super User
Super User

HI @Anonymous ,

 

Here's what I would do:

  • duplicate the freetext column
  • lowercase the duplicate (or uppercase) as M is case-sensitive
  • remove special characters from the duplicate
  • and then do the search using List.Position

Please see attached pbix for details

 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.