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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
scign
Frequent Visitor

Filter text field on containing at least one keyword in a list

I have:

1. a table of product purchases (np = around 160,000 records) with several fields including a text description field, and

2. a separate list of keywords (nk = around 90 rows) and partial keywords like "fuse" and "calibrat" (which covers "calibrate", "calibration", "calibrating", etc). The keyword list may be added to.

 

I need:

- a table of purchases where the description field contains at least one of the keywords in the list.

 

Is there an easy way to do this?

 

My thought was to do the following:

1. full outer join of the two tables to get one row for each keyword for every purchase, so that I would have (np * nk) rows,

2. add new column with a text search of the keyword in the description

3. filter where the text search yields a true

4. remove duplicate purchase records

 

However I have been stumped on how to do a full outer join without a matching column....

 

OK so while I was typing that last line I had a brainwave. I was stuck on how to join the two tables without a matching column so I just created a column in each table with "1" as the value for all rows and joined on those columns. That gave me the full outer join and I continued from #2 above and got my filtered list.

 

I'm still curious to find out if there's an easier way than that, as it seems like a rather sledgehammer approach to the nut that I have.

 

Thoughts?

2 ACCEPTED SOLUTIONS
drewlewis15
Solution Specialist
Solution Specialist
v-shex-msft
Community Support
Community Support

Hi @scign,

 

You can try to use below formula to get the matched table.(I found some ideas to modify my formula from @drewlewis15's link)

Matched Table = CALCULATETABLE(Records,FILTER(ADDCOLUMNS(Records,"Contains",FIRSTNONBLANK(FILTER(VALUES(Keywords[Keyword]),
SEARCH(Keywords[Keyword],[Description],1,0)),[Keyword])),[Contains]<>BLANK()))

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

4 REPLIES 4
v-shex-msft
Community Support
Community Support

Hi @scign,

 

You can try to use below formula to get the matched table.(I found some ideas to modify my formula from @drewlewis15's link)

Matched Table = CALCULATETABLE(Records,FILTER(ADDCOLUMNS(Records,"Contains",FIRSTNONBLANK(FILTER(VALUES(Keywords[Keyword]),
SEARCH(Keywords[Keyword],[Description],1,0)),[Keyword])),[Contains]<>BLANK()))

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Ashish_Mathur
Super User
Super User

Hi,

 

Share a dataset and show the expected result.


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

If you want to full join 2 tables without matching key column, you can just add a custom column with the other table, like:

 

= Table.AddColumn(Table1,"Table2", each Table2)

 

An alternative solution for your requirements would be to split your descriptions on any of the keywords and then take the results that have multiple items, like: 

 

= Table.SelectRows(Source, each List.Count(Splitter.SplitTextByAnyDelimiter(Keywords)([Description])) > 1)

 

Specializing in Power Query Formula Language (M)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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