cancel
Showing results for 
Search instead for 
Did you mean: 
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
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

Thank you 2022 Review

2022 Monthly Feature Releases

We had a great 2022 with a ton of feature releases to help you drive a data culture.