Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Search a substring in string from another table with DAX

Hi everyone,

 

I need help figuring out how to search for a substring in another table with DAX. My data looks like this:

 

Table 1:

 

Customer IDProducts IDs
AA_019442123456A;123456B
BB_149432123456A
CC_924742123456F;123456C
DD_127194123456C
EE_373878123456E

 

 

Table 2 (unrelated and unique ids):

 

Product IDDescription
123456AAAAAAAAAAAA
123456BBBBBBBBBBBBBB
123456CCCCCCCCCCCCC

 

I need to compare every substring in the column "Product IDs" in Table 1 with the column "Product ID" in Table 2.

My expected outcome would be:

  • If both subtrings match, then I should get the description concatenated
  • If just one of the substrings match, then I should get only the description for the ids that math
  • If there is no match, then BLANK
Customer IDProduct IDsDescription
AA_019442123456A;123456BAAAAAAAAAAA;BBBBBBBBBBBBB
BB_149432123456AAAAAAAAAAAA
CC_924742123456F;123456CCCCCCCCCCCCC
DD_127194123456CCCCCCCCCCCCC
EE_373878123456E 

 

I know that this could easily be accomplished with PowerQuery/M by splitting every product IDs by the delimiter ";" and matching them, but I'm asking for help with DAX because of how the PowerBI model has been made.

 

I thought at first the SEARCH function or the CONTAINSSTRING one would work, but I didn't manage to write the code for it, because I don't know how to search for contents in another unrelated table.

 

Thanks everyone in advance!!

1 ACCEPTED SOLUTION
barritown
Super User
Super User

Hi @Anonymous,

 

You can try this solution:

barritown_0-1683796459036.png

 

However, you may not like some of its drawbacks:

- sorting in Products IDs may not match sorting in Description;

- if you have duplicates in Products IDs, they will have only one match in Description.

 

If those things don't bother you, it should be fine.

 

Here's the same calculated column in the text format:

Description = 
CONCATENATEX ( FILTER ( ADDCOLUMNS ( Table2,                
                                     "Presence", 
                                     CONTAINSSTRING ( [Products IDs], [Product ID] ) ), 
                        [Presence] = TRUE () ), 
               [Description], 
               ";" )

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

 

View solution in original post

2 REPLIES 2
barritown
Super User
Super User

Hi @Anonymous,

 

You can try this solution:

barritown_0-1683796459036.png

 

However, you may not like some of its drawbacks:

- sorting in Products IDs may not match sorting in Description;

- if you have duplicates in Products IDs, they will have only one match in Description.

 

If those things don't bother you, it should be fine.

 

Here's the same calculated column in the text format:

Description = 
CONCATENATEX ( FILTER ( ADDCOLUMNS ( Table2,                
                                     "Presence", 
                                     CONTAINSSTRING ( [Products IDs], [Product ID] ) ), 
                        [Presence] = TRUE () ), 
               [Description], 
               ";" )

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

 

Barritown,

Thanks for this tip it is very usefull but I have a question. I have a situation where I want the result to be the sum of the the values rather than concatenate them. Is that possible?

Thanks

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.