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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
technosmith
Frequent Visitor

Find /compare text string segment between two tables

I am needing to create a new column in table 1 based on the contents of a column in table 2. if any of the text in the rows of table 2 are present in the string field in table 1 , then the contents of the new column field must equal the string segment found in table 2.

 

The red text in the "code" field in table 1 would be the desired output

 

Any help appreciated

 

technosmith_0-1693644740940.png

 

1 ACCEPTED SOLUTION

Thanks @technosmith  🙂

 

I have attached a small PBIX with one approach.

 

Here is an extract of code for Table 1 with the Code column added:

let
    // ... Earlier steps here
    // Next step finds first matching Code from Table 2
    #"Added Code" = Table.AddColumn(#"Changed Type", "Code", each let CurrentCodeGroup = [CodeGroup] in List.First(List.Select(#"Table 2"[Code],each Text.Contains(CurrentCodeGroup,_))), type text)
in
    #"Added Code"

The Added Code step finds the first Code from Table 2 that is contained in the CodeGroup string.

A null value should be returned in the case of no match.

 

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

6 REPLIES 6
technosmith
Frequent Visitor

Thanks @OwenAuger 

The PBIX visually would achieve what I need. 

Your solution may work, however, I think I may have oversimplified the graphic supporting my question...

In your PBIX attachment I only noted one table, while I will have two tables. I did note in when looking at the Power query editor I did see the two tables. I am not yet familiar enough with Power query editor to understand your proposed solution. Thanks again for taking the time to respond!

 

technosmith_0-1693736249387.png

After playing around with the avdanced editor using @OwenAuger solution I applied it successfully to my data. Thanks @OwenAuger !

@technosmith glad it helped!

Yes, both tables are present in Power Query but I had only loaded one. You can certainly load both to the data model if needed 🙂


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn
OwenAuger
Super User
Super User

Hi @technosmith 

What do you want in the new column in the case of multiple matches? Concatenate them in some way? Or can we assume that will never happen?

 

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

Thanks for responding Owen,

That should never happen.

There should always only be one hit in the "CodeGroup"

Thanks @technosmith  🙂

 

I have attached a small PBIX with one approach.

 

Here is an extract of code for Table 1 with the Code column added:

let
    // ... Earlier steps here
    // Next step finds first matching Code from Table 2
    #"Added Code" = Table.AddColumn(#"Changed Type", "Code", each let CurrentCodeGroup = [CodeGroup] in List.First(List.Select(#"Table 2"[Code],each Text.Contains(CurrentCodeGroup,_))), type text)
in
    #"Added Code"

The Added Code step finds the first Code from Table 2 that is contained in the CodeGroup string.

A null value should be returned in the case of no match.

 

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.