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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
GDemnerIMUK
Regular Visitor

Check string for values in other table

Hey guys, 

 

I have a list of social media posts about companies and i want to categorise which company this is. 

 

I have a list of all the potential companies that could be there and i want to search the subject string to see if it contains one of the values in this table. 

 

I then want to return the value it found. 

 

Is there a good way to do this? 

 

Thanks, 

George 

1 ACCEPTED SOLUTION

Say you have your posts in a table, then you can add a column with this formula:

 

List.First(List.Select(ListOfPotentialCompanies, (x) => Text.Contains([Post], x))) 

You can also paste this code into the advanced editor to see how this works:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8kjMyclX8M1MLsovzk8rUYrViVbyVMjJL0tVCMgvTy1ScPJUio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Post = _t]),
    ListOfPotentialCompanies = {"Microsoft"},
    #"Added Custom" = Table.AddColumn(Source, "Custom", each List.First(List.Select(ListOfPotentialCompanies, (x) => Text.Contains([Post], x))))
in
    #"Added Custom" 

As you'll see, only the first value from the possible list of matches is selected, but you can omit that part of the formula if you want to retrieve all matches instead.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

8 REPLIES 8
Greg_Deckler
Super User
Super User

Hmmm, maybe if you could somehow split out the text into a table and then use GENERATE against this table and your other table along with maybe an ADDCOLUMN or something. Sounds nasty and computational expensive in DAX.

 

Or are you looking for a Power Query solution?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hey, 
Ideally looking for a solution in power query. The idea is that when these have been categorised i can then slice all the data from one slicer 🙂 

Ahh, in that case, @ImkeF is your best bet!



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Say you have your posts in a table, then you can add a column with this formula:

 

List.First(List.Select(ListOfPotentialCompanies, (x) => Text.Contains([Post], x))) 

You can also paste this code into the advanced editor to see how this works:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8kjMyclX8M1MLsovzk8rUYrViVbyVMjJL0tVCMgvTy1ScPJUio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Post = _t]),
    ListOfPotentialCompanies = {"Microsoft"},
    #"Added Custom" = Table.AddColumn(Source, "Custom", each List.First(List.Select(ListOfPotentialCompanies, (x) => Text.Contains([Post], x))))
in
    #"Added Custom" 

As you'll see, only the first value from the possible list of matches is selected, but you can omit that part of the formula if you want to retrieve all matches instead.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

Hi @ImkeF ! 

 

I was having the exact same problem and I have tried your solution but I just can't refer "TheListofPotentialCompanies" in my M formula. 

 

Any idea why? Thank you so much 🙂 

This video is not particularly good, but hopefully helpful: http://community.powerbi.com/t5/Webinars-and-Video-Gallery/Power-BI-Forum-Help-How-to-integrate-M-co... 

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

Hi @ImkeF ! Thank you so much for your help! I've ended up creating a list with the values I want to use so I can use it within the formula.

However, I still get an error when I type: List.First(List.Select(#"Lista Assinaturas", (x) => Text.Contains([Data Base], x))))

 

Any idea why?

 

Any help would be very welcome 🙂 

 

Thank you!

 

Pedro 

Hi @Anonymous ,

could you please create a sample file and paste the download link here?

Thanks,

Imke

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.