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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Bijan
New Member

Contains/search

Hi there,

I am struggeling with a Contains formula. Can you please help me?

I want to create a columns with DAX formula that is :

If rows in Column A contains the value from Column B then row value of Column C.

Column B and C are from a same table and A is from another table.

I don't want to use lookup value, because the Column B is part of the text in Column A, and it is not fully matching.

Should I use Contains or Search? or anything else? and how would it be?

Hope that makes sense.

Thank you so much!

Bijan

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @Bijan ,

I created a sample pbix file(see the attachment), please check if that is what you want.

1. Assume that you have the below 2 tables data

Table1:

yingyinr_0-1672911662954.png

Table2:

yingyinr_1-1672911676151.png

2. Create a calculated column as below in Table1 which has Column A

Column = 
CALCULATE (
    MAX ( 'Table2'[C] ),
    FILTER ( 'Table2', SEARCH ( 'Table2'[B], 'Table1'[A], 1, 0 ) > 0 )
)

yingyinr_2-1672911788918.png

If the above one can't help you get the desired result, please provide more raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-yiruan-msft
Community Support
Community Support

Hi @Bijan ,

I created a sample pbix file(see the attachment), please check if that is what you want.

1. Assume that you have the below 2 tables data

Table1:

yingyinr_0-1672911662954.png

Table2:

yingyinr_1-1672911676151.png

2. Create a calculated column as below in Table1 which has Column A

Column = 
CALCULATE (
    MAX ( 'Table2'[C] ),
    FILTER ( 'Table2', SEARCH ( 'Table2'[B], 'Table1'[A], 1, 0 ) > 0 )
)

yingyinr_2-1672911788918.png

If the above one can't help you get the desired result, please provide more raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you so much! you saved my life!

AlexisOlson
Super User
Super User

Try something like this:

VAR B_in_A =
    FILTER (
        VALUES ( Table2[Column A] ),
        CONTAINSSTRING ( Table2[Column A], Table1[Column B] )
    )
VAR Result =
    IF ( ISEMPTY ( B_in_A ), BLANK(), Table1[Column C] )
RETURN
    Result

Replace BLANK() with whatever result you want if A doesn't contain B.

Thanks a lot for your response!
I am creating the new column in the table A. and it doesn't let me to add a column from Table B, as your formula order. It lets me to add table B column in the place of A in your formula.

@Bijan My DAX was assuming you were defining a new column in Table1 (the one with Column B and Column C).

 

If the tables are set up as @v-yiruan-msft has them, you add the column to Table2 like this:

AlexisOlson_0-1672931483244.png

Thank you so much!

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.

Top Solution Authors