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
Turnipface
Advocate I
Advocate I

Count keywords from text column, link them to specified categories

Hi all,

Similar to the example here (which didn't quite work for me - maybe due to the relationships) i need to do the following:
Recognize and count the number of keyword occurances from the below 3 tables:

 

Table 1

Transaction ID
1
2
3
4
5
6
7
8
9
10

 

Table 2

Transaction IDNotesCategory
1Today's purchase included apples and orangesFruit
2We had some beets and red peppersVegetable
2More text strings, and fresh orangesFruit
2lorem ipsum lorem ipsum strawberries and orangesFruit
3A treasure chest full of bananasFruit
4Turnips are not fruitsVegetable
4Colourful pretty avocadosFruit
8A table made its way downtownFurniture
9Some people hate 3-legged chairsFurniture
10A truckload of broccoli and turnipsVegetable

 

Table 3

CategoryDetails
FruitOranges, Apples, Strawberries, Avocados, Bananas
VegetableBroccoli, Red Peppers, Turnips, Beets
FurnitureTable, Chairs

 

 

This is how all 3 are related to each other

 

Relationships.png

 

More specifically, what I'm looking to do is count how many times each individual Keyword has been mentioned in the Notes section. Not only that, but keep the current link so that i can later filter by Transaction ID or any other parameter that belongs to the ID (not mentioned in Table1)

For example, when i select specific Category item like Fruit, it should count how many occurences of each of of its Keywords exist in the Notes section.

I've also got the mock .pbix file if that'll help.


What would be a good way to approach this? Any help will be highly appreciated here 🙂

1 ACCEPTED SOLUTION

Hi @Turnipface,

 

In this scenario, you can use the formula below to create a new measure instead, and then show the measure on the report. Smiley Happy

Measure = SUMX(Table2,COUNTROWS (
    FILTER (
        RELATEDTABLE ( 'Table3 (2)' ),
        SEARCH ( 'Table3 (2)'[Details], Table2[Notes],, 0 ) > 0
    )
))

r1.PNG

 

Regards

View solution in original post

4 REPLIES 4
v-ljerr-msft
Employee
Employee

Hi @Turnipface,

 

If I understand you correctly, you should be able to follow steps below to count the keywords in your scenario.

 

1. Duplicate Table3 in Query Editor, and split the Details column by Comma to Rows 

 

s2.PNG

 

2. Trim the new Details column, and then Close&Apply.

 

trim2.PNG

 

3. Create a relationship between Table3 and the duplicated table.

 

relation1.PNG

 

4. Then you should be able to use the formula below to create a new calculate column in Table to to get the Keywords count for each Notes.

KeywordsCount = 
COUNTROWS (
    FILTER (
        RELATEDTABLE ( 'Table3 (2)' ),
        SEARCH ( 'Table3 (2)'[Details], Table2[Notes],, 0 ) > 0
    )
)

c2.PNG

r1.PNG

Here is the sample pbix file for your reference. Smiley Happy

 

Regards

Hi v-ljerr-msft, 

Thanks for your reply! This is definitelly a move in the right direction and splitting the items in different columns is helpful!

However, the "Details" are linked to the Notes via the Category so selecting Apple, for example, will also show other results from the Notes that have the category of Fruit.

Fruits and stuf.PNG

 

What i'm looking to do is count the times when Apples, in particular, was used in the Notes. So the result of 7 up there, should in fact be 1 and linking only to the result on the bottom left.

 

What would be the thing to explore that can help me achieve that?

Hi @Turnipface,

 

In this scenario, you can use the formula below to create a new measure instead, and then show the measure on the report. Smiley Happy

Measure = SUMX(Table2,COUNTROWS (
    FILTER (
        RELATEDTABLE ( 'Table3 (2)' ),
        SEARCH ( 'Table3 (2)'[Details], Table2[Notes],, 0 ) > 0
    )
))

r1.PNG

 

Regards

Greg_Deckler
Super User
Super User

You could brute force it by creating a series of columns using SEARCH function that would return a 1 if a keyword was found or a 0 if not that would also take the category into account and then another column that summed all of those columns, for example:

 

Apples = IF([Category]="Fruit",IF(SEARCH([Notes],"apple",0),1,0),0)

 


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.