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
PowerBI123456
Post Partisan
Post Partisan

Searching for specific combination of codes from different table

Hopefully this makes sense, but I am trying to search in column B (my codes) to see if it contains any specific combination of codes from columns A & B from a different table. For example, ID: 11111111 contains codes 12345 & 10112 so thats a match. ID 2222222 contains codes 88373 & 12345 so thats a match. ID 3333333 contains codes 97478 and B5768 so thats a match. 

 

Image 1.PNG

 

Image 2.PNG

 

There are over 400,000 different combinations and I am searching 100,000s of rows. 

 

Any tips would be appreciated!! 

 

11 REPLIES 11
Anonymous
Not applicable

Hi @PowerBI123456

 

Create a measure as below:

 

Match = 
var a =SEARCH(MAX('Table (2)'[Column 1 code]),MAX('Table'[Codes]),1,0)
var b=SEARCH(MAX('Table (2)'[Column 2 code]),MAX('Table'[Codes]),1,0)
Return
IF(a<>0&&b<>0,"match","Not found")

 

And you will see:

Annotation 2020-06-30 110314.png

For the related .pbix file,pls click here.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!
AllisonKennedy
Super User
Super User

@PowerBI123456 have updated with correct syntax (it had some ) in wrong places)

I'm thinking something like this could work as calculated COLUMN in Table1: 

 

Match = IF(COUNTROWS(FILTER(Table2, CONTAINSSTRING(Table1[Codes],Table2[Column 1 Code]) && CONTAINSSTRING(Table1[Codes],Table2[Column 2 Code])))>0, "Match", "Not Found")

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

@AllisonKennedy good solution but my only concern will be the performance given the # of rows. @PowerBI123456 let us know if @AllisonKennedy solution performed ok, if not then I have some ideas which I would like to try but first let's try the solution you have in place. Maybe this is a good solution.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Thanks so much! However, when I tried using that formula, its been running for over 15 minutes now, and still running. 

 

Anyway to do this faster? Also, any way to bring back what the match was? 

@parry2k  You're up - keen to hear your thoughts on optimization. 

 

@PowerBI123456  what do you mean by bring back what the match was? Do you just want a text value of Column1, Column 2?


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

@AllisonKennedy  - yes, anyway to know what the value was from column 1 and column 2?

 

@Anonymous Thanks a lot! But its not working for me, I am not getting any matches even though I know there are some. 

 

@parry2k would love to hear your thoughts on optimizing. 

 

Thanks everyone!!

Anonymous
Not applicable

Hi @PowerBI123456 ,

 

What will return if you use below dax expression:

 

Match = 
var a =SEARCH(MAX('Table (2)'[Column 1 code]),MAX('Table'[Codes]),1,0)
var b=SEARCH(MAX('Table (2)'[Column 2 code]),MAX('Table'[Codes]),1,0)
Return
a&" "&b

 

Show me your screenshot..

And have you checked my .pbix file?Can you find the reason why my side has shown the correct result while your side returned error?

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

@Anonymous  Should this be a measure or a column?

Anonymous
Not applicable

Hi @PowerBI123456 

 

This is a measure.

What I suggested in the last reply is also a measure,never copy it in a calculated column,otherwise you will get blank values.

 

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

@Anonymous Thanks, but I think the reason why its not working for me is because the column 1 and column 2 have duplicate codes in my file. For example:

 

PowerBI123456_0-1594402391264.png

 

 

@parry2k Hi, did you have a better way of doing this? 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.