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
Julio-YYC
Helper II
Helper II

Comparing a Value from one table to a string in another table

Hi everyone, 

I have the following situation:

1-) I have a table called 'Expense Category' as shown below:

JulioYYC_0-1668886788692.png

2-) I have a second table with credit card statement called 'CreditCard':

JulioYYC_1-1668886890407.png

 

What I need to achieve:

- I want Power BI to compare the column [Expense Detail] to the column [Detail] in the first table. If the 'Expese Detail' description contains any of the words in the column 'Detail', power BI will bring the correspondent 'Category' value to my CreditCard table in a new column 'Category' just beside the 'Account' column

      Something like this: 

JulioYYC_2-1668887690967.png

 

any thoughts ?

 

thanks!

Julio

 

 

                           

 

 

 

 

2 ACCEPTED SOLUTIONS
v-cgao-msft
Community Support
Community Support

Hi @Julio-YYC ,

Please try like:

= Table.AddColumn(#"Changed Type", "Category", each Table.SelectRows(#"Expense Category",(x)=>Text.Contains([Expense Detail],x[Detail],Comparer.OrdinalIgnoreCase))[Category]{0})

vcgaomsft_0-1669102041727.png

and then repalce error.

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

View solution in original post

Hi Bifinity_75, I tested your solution, and it worked great also. I've got two distinct solutions for the same issue. appreciated. thanks. 

View solution in original post

6 REPLIES 6
Bifinity_75
Solution Sage
Solution Sage

Hi @Julio-YYC , try this calculate column:

 

Category = 
    maxx(filter('Expense Category' , 
    search('Expense Category'[Detail], CreditCard[Expense Detail],,0)>0),'Expense Category'[Detail]
        )

Bifinity_75_0-1669105137648.png

 

Best regards

Hi Bifinity_75, I tested your solution, and it worked great also. I've got two distinct solutions for the same issue. appreciated. thanks. 

v-cgao-msft
Community Support
Community Support

Hi @Julio-YYC ,

Please try like:

= Table.AddColumn(#"Changed Type", "Category", each Table.SelectRows(#"Expense Category",(x)=>Text.Contains([Expense Detail],x[Detail],Comparer.OrdinalIgnoreCase))[Category]{0})

vcgaomsft_0-1669102041727.png

and then repalce error.

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

it worked nice Gao, thanks! one more question, in a case where there is no match between 'Expense Detail' and the 'Detail' column, how can I get 'Others' as a result for the Category instead of the error message shown below? 

 

JulioYYC_0-1669782123250.png

thanks!

Julio

 

Julio-YYC
Helper II
Helper II

Good point daXtreme...! I'm gonna follow your suggestion above...many thanks!

 

daXtreme
Solution Sage
Solution Sage

I wouldn't do that. It'll be painfully slow on a bigger data set. Instead, I'd use Power Query to break down the phrases into individual words stored in one column and then use such a table to match against these words. This is acually how it should be handled in a professional model.

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.

Top Solution Authors