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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
TIGER8855
Helper I
Helper I

Compare text string between two tables (Not exact)

I have columns in seperate tables and I need to identify if there is match between the columns. The text in table 1 will be exact where as the text in table 2 may contain the text from table 1 amongst other text. I cannot create a relationship between these table columns as some of the values in Table 1 are duplicated.

 

If possible, I want a new column in table 1 which will have a yes or no for each row to indicate if there is a match in Table 2. Using DAX would be the preference. Below is a sample of the data

 

Table 1EXPECTED RESULT
AAA-1111Yes
BBB-2222No
CCC-3333Yes
AAA-1111Yes
DDD-4444No

 

Table 2
AAA-1111 This is a sample
Sample Data. EEE-5555. Testing
Test of data CCC-3333. 
HHH-8888.
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @TIGER8855 ,

You can create a calculated column as below in 'Table 1', please find the details in the attachment.

Column =
VAR _t2col =
    CALCULATE (
        MAX ( 'Table 2'[Column1] ),
        FILTER (
            'Table 2',
            IFERROR ( SEARCH ( 'Table 1'[Column1], 'Table 2'[Column1], 1, 0 ), 0 ) > 0
        )
    )
RETURN
    IF ( ISBLANK ( _t2col ), "No", "Yes" )

vyiruanmsft_0-1682403381048.png

Best Regards

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi @TIGER8855 ,

You can create a calculated column as below in 'Table 1', please find the details in the attachment.

Column =
VAR _t2col =
    CALCULATE (
        MAX ( 'Table 2'[Column1] ),
        FILTER (
            'Table 2',
            IFERROR ( SEARCH ( 'Table 1'[Column1], 'Table 2'[Column1], 1, 0 ), 0 ) > 0
        )
    )
RETURN
    IF ( ISBLANK ( _t2col ), "No", "Yes" )

vyiruanmsft_0-1682403381048.png

Best Regards

Thank you @Anonymous ! That worked. The solution provided was well written.

 

I have one more request if you could help which is related. I also need an additional column that uses the same concept against the same source data with the only difference that it also needs to filter against an additional column in Table2 that has either TRUE or FALSE in it. So if Column1 from Table1 has a match against the text string in Table2 Column1 AND Column 2 is TRUE then it would return a Yes in the new Column in Table1. If not it would return a No. Below is an example of the expected result for new Column:

 

Table1

Column1         Column
AAA-1111No
BBB-2222No
CCC-3333Yes
AAA-1111No
DDD-4444No

 

Table 2

Column1                                           Column 2
AAA-1111 This is a sampleFALSE
Sample Data. EEE-5555. TestingTRUE
Test of data CCC-3333. TRUE
HHH-8888.FALSE
Anonymous
Not applicable

Hi @TIGER8855 ,

You can create a calculated column as below similar to the previous one  to get it:

Column =
VAR _t2col =
    CALCULATE (
        MAX ( 'Table 2'[Column1] ),
        FILTER (
            'Table 2',
            IFERROR ( SEARCH ( 'Table 1'[Column1], 'Table 2'[Column1], 1, 0 ), 0 ) > 0
                && 'Table 2'[Column 2] = "TRUE"
        )
    )
RETURN
    IF ( ISBLANK ( _t2col ), "No", "Yes" )

vyiruanmsft_0-1682559093652.png

Best Regards

@Anonymous thank you! Worked perfectly.

Adamboer
Responsive Resident
Responsive Resident

Yes, it is possible to use DAX to create a new column in Table 1 that indicates whether there is a match in Table 2. One approach could be to use the CONTAINS function to check if the text in Table 2 contains the text in Table 1.

Here is an example DAX formula that you can use to create a new column in Table 1:

=IF(COUNTROWS(FILTER(Table2,CONTAINS(Table2[Text],Table1[Column])))>0,"Yes","No")

This formula uses the FILTER function to identify rows in Table 2 where the text in the [Text] column contains the text in the [Column] column of Table 1. The CONTAINS function performs the actual text comparison. If the FILTER function returns any rows, then the COUNTROWS function will return a value greater than zero, indicating that there is a match. The IF function then returns "Yes" if there is a match, and "No" otherwise.

Note that this formula assumes that the name of the [Text] column in Table 2 is "Text". You may need to adjust the formula accordingly if the actual name of the column is different.

Also, keep in mind that this approach may not be very efficient for large tables, as it requires scanning the entire [Text] column of Table 2 for each row in Table 1. If performance is a concern, you may want to consider other approaches, such as using Power Query to merge the two tables based on a partial match of the [Text] and [Column] columns.

Thanks for the response @Adamboer . I tried the suggested formula however I get the error "Too few arguments were passed to the CONTAINS function. The minimum argument count for the function is 3.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.