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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
yyyy
Frequent Visitor

how to add a value from another table when a string contains this value?

I need some help to achieve this, hope someone can help. 

 

I have a table with a column named 'Title'. 

I have another table with a column named 'Code'. 

What I need to achieve is: 
If table1.Title contains a value that is present in tabl2.Code, I want to see this code in Table1. 

 

Example: 

Table1
CODE 

ABC

DEF

XYZ

 

Table2 has a column TITLE, and I want to add a column CODE. 

Example: 

CODE        TITLE

DEF            this title contains DEF, so I want to see this as code

ABC           this title contains ABC
                  this title contains QQQ. QQQ is not present in table one, so code must stay empty

 

 

 

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

@EvL1973 

You are right. Following is amended 

Code =
VAR T1 =
    FILTER ( Table1, CONTAINSSTRING ( Table2[Title], Table1[Code] ) )
RETURN
    IF ( NOT ISEMPTY ( T1 ), MAXX ( T1, Table1[Code] ) )

 

View solution in original post

3 REPLIES 3
tamerj1
Super User
Super User

@EvL1973 

You are right. Following is amended 

Code =
VAR T1 =
    FILTER ( Table1, CONTAINSSTRING ( Table2[Title], Table1[Code] ) )
RETURN
    IF ( NOT ISEMPTY ( T1 ), MAXX ( T1, Table1[Code] ) )

 

EvL1973
Frequent Visitor

I think the provided solution doesn't work: 

I used this to test it:  

Table1
table1table1

Table 2

table 2table 2

 

New calculated column in table 2: 

calculatedcolumn.png

 

 

 

tamerj1
Super User
Super User

Hi @yyyy 
Seems there is some confusion or typo mistakes in the question. I will assume that Table2 has the column [Title] that is a text which might contain one of codes available in Table1[Code] and you want to create a new column in Table2 that contains the code from Table1 if it existis with the title text otherwise return blank.

Code =
IF (
    NOT ISEMPTY ( FILTER ( Table1, CONTAINSSTRING ( Table2[Title], Table1[Code] ) ) ),
    Table1[Code]
)

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.