Forum Discussion
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:
2-) I have a second table with credit card statement called 'CreditCard':
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:
any thoughts ?
thanks!
Julio
- Anonymous3 years ago
Hi Anonymous ,
Please try like:= Table.AddColumn(#"Changed Type", "Category", each Table.SelectRows(#"Expense Category",(x)=>Text.Contains([Expense Detail],x[Detail],Comparer.OrdinalIgnoreCase))[Category]{0})and then repalce error.
Best Regards,
Gao
Community Support TeamIf 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
- Anonymous3 years ago
Hi Bifinity_75, I tested your solution, and it worked great also. I've got two distinct solutions for the same issue. appreciated. thanks.
6 Replies
- AnonymousNot applicable
Hi Anonymous ,
Please try like:= Table.AddColumn(#"Changed Type", "Category", each Table.SelectRows(#"Expense Category",(x)=>Text.Contains([Expense Detail],x[Detail],Comparer.OrdinalIgnoreCase))[Category]{0})and then repalce error.
Best Regards,
Gao
Community Support TeamIf 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
- AnonymousNot applicable
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?
thanks!
Julio
- daXtremeSolution 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.
- AnonymousNot applicable
Good point daXtreme...! I'm gonna follow your suggestion above...many thanks!
- Bifinity_75Solution Sage
Hi Anonymous , try this calculate column:
Category = maxx(filter('Expense Category' , search('Expense Category'[Detail], CreditCard[Expense Detail],,0)>0),'Expense Category'[Detail] )Best regards
- AnonymousNot applicable
Hi Bifinity_75, I tested your solution, and it worked great also. I've got two distinct solutions for the same issue. appreciated. thanks.