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
robbieinoz
Frequent Visitor

Data categorization and labeling based on a criteria list

Hi!

 

I have a very large list of transactions and I am attempting to use powerbi to categorize these transactions based on a narrative field in the transaction list, containing certain text. I have seen the following solution which largely achieves what I'd like to do based on a conditional column and seems great for a small number of criteria you'd like to test.

 

http://community.powerbi.com/t5/Desktop/Categorize-column-if-it-contains-part-of-text/m-p/134596#M57...

 

However, my problem is that I have about 100 criteria flags that can be used to categorize transactions. Ideally, I'd like to have a category table with a flag field and a category field - that the transaction narrative can be tested against. Like so:

 

Transactions table I'd like to categorize by text found in the narrative field:

 

Transaction #Narrative
1Shop 123
2Shop 241
3Online 122
4Chargeback
5Tax
6Refund 123

 

 

Criteria Table - this has about 100 criteria to test against:

 

Narrative ContainsCategory
ShopIn store
OnlineOnline
ChargebackCC
TaxTax
RefundIn store

 

Ideally I'd be able to create a table like so;

 

Transaction #NarrativeCategory
1Shop 123In store
2Shop 241In store
3Online 122Online
4ChargebackCC
5TaxTax
6Refund 123In store

 

Any ideas? I'm totally lost. In excel for each row in the transaction table, I'd iterate over the category flag list - either through an array formula or a for loop in VBA - and return the corresponding value from the category column if a match is found (first match is fine). But I'm new to BI so I'm a tad lost....

 

Thanks!

1 ACCEPTED SOLUTION

Ok I have solved this. Here's how:

 

I created a new column in my transaction table with the following formula:

 

MatchFound= 
FIRSTNONBLANK(
FILTER(
values('Keyword Table'[Narrative Contains]),
search('Keyword Table'[Narrative Contains],'Transaction list'[Narrative],1,0)
)
,1)

This formula returns the matching value found within the narrative string. I can then use this with a lookup formula, to return the corresponding category:

category = 
LOOKUPVALUE(
'Keyword Table'[Category],'Keyword Table'[Narrative Contains],'Transaction list'[MatchFound]
)

And voila! My transaction list is now categorized by searching the a narrative field to see if it contains any item from a list of keywords paired with categories...

 

final Match Table.png

View solution in original post

7 REPLIES 7
Vvelarde
Community Champion
Community Champion

@robbieinoz

 

hi, i know that exist much better solutions but lets try:

 

1. Insert in both tables a Custom Column with the Value of 1.

 

Img1.png

 

img2.png

 

2. Merge both Tables in a New Query

 

Img3.png

 

3. You obtain a table like this:

 

Img4.png

 

4. Expand the Table

Img5.png

 

5. Insert a New Custom Column: 

 

Img6.png

 

6. Filter this Column to only 1 

 

Img7.png

 

7. Delete the other Columns

 

Img8.png

 

8. Ready

 

Regards

 

Victor

Lima - Peru




Lima - Peru

Think this is a good solution for smaller datasets. Thank you so much for taking the time to post @Vvelarde

 

However with my dataset I have about 2m rows in my initial transaction listing - and about 100 criteria - so this would result in a 200m row table. I'm a little afraid to try this as I feel this surely would overload things...

Any other ideas for large datasets?

I found this solution for at least idenitfiying if there is a keyword match, but I still can't figure out how to return the corresponding category. This function can be thought of like a "containsx" formula.

 

In my transaction table I added a column with the following formula:

 

KeywordMatch = if(
SUMX('Keyword Table',
find(upper('Keyword Table'[Narrative Contains]),upper('Transaction list'[Narrative]),,0))
>0,"Match","No Match")

Which gives me this result:

 

matchTable.png

 

But I still can't figure out how to return the corresponding category...  

Ok I have solved this. Here's how:

 

I created a new column in my transaction table with the following formula:

 

MatchFound= 
FIRSTNONBLANK(
FILTER(
values('Keyword Table'[Narrative Contains]),
search('Keyword Table'[Narrative Contains],'Transaction list'[Narrative],1,0)
)
,1)

This formula returns the matching value found within the narrative string. I can then use this with a lookup formula, to return the corresponding category:

category = 
LOOKUPVALUE(
'Keyword Table'[Category],'Keyword Table'[Narrative Contains],'Transaction list'[MatchFound]
)

And voila! My transaction list is now categorized by searching the a narrative field to see if it contains any item from a list of keywords paired with categories...

 

final Match Table.png

Anonymous
Not applicable

Thanks, it works for me. Perfect

Hi,

I'm using your solution on a similar DB.

My only issue is that I don't know how to customized the matching algortithm to include only exact matches. For example, one of my keyword is "pers" but this formula gives a match also when "personnel" is found. Do you know how I can request exact matches?

 

Thanks!

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.