cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Julio-YYC
Helper I
Helper I

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 I
Helper I

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

 

daXtreme
Super User
Super User

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
May 2023 update

Power BI May 2023 Update

Find out more about the May 2023 update.

Submit your Data Story

Data Stories Gallery

Share your Data Story with the Community in the Data Stories Gallery.

Top Solution Authors