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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

How to check if a string from a column in table A contains in table B and perform an action?

Hi Everyone,

I have a question on DAX formula which allows me to iterate over a column in one table and perform a concatnate action on another column if the value exsists in that column.

 

Example
I Have tableA as shown below

PathUsername
A001@test.net|B001@test.net|C001@test.net
A001@test.net|B001@test.net|C001@test.net|D001@test.net

 

(Image view so the columns are shown properly)stramzik_0-1595321951386.png

 

I Also have tableB as shown below

SearchStringAddString
D001@test.netE001@test.net
C001@test.netF001@test.net

(Image view so the columns are shown properly) test.png

 

What I'm trying to do is check if the each values in "SearchString" of tableB is in every row of "PathUsername" of tableA and if yes then concatnate the value of "AddString" corresponding to that "SearchString" from tableB to "PathUsername" of tableA as below

PathUsernameProxyUsername
A001@test.net|B001@test.net|C001@test.netA001@test.net|B001@test.net|C001@test.net|F001@test.net
A001@test.net|B001@test.net|C001@test.net|D001@test.netA001@test.net|B001@test.net|C001@test.net|D001@test.net|E001@test.net|F001@test.net

(Image view below so the columns are shown properly)stramzik_1-1595322004366.png

 

If you notice, if there are multiple values it also needs to be concatnated(row two of above table includes the add string of C001 and also D001)

 

Kindly advise how I can acheive this in DAX thank you.

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@Anonymous , Try like

concatenatex(filter(tableB, containsstring(tableA[PathUsername], tableB[SearchString])),tableB[AddString],"|")

View solution in original post

Anonymous
Not applicable

You may use this approach.

 

ProxyUserName =
tableA[PathUsername]
    & CONCATENATEX (
        tableB,
        IF (
            NOT (
                ISBLANK ( SEARCH ( tableB[SearchString], tableA[PathUsername], 1, BLANK () ) )
            ),
            tableB[AddString],
            BLANK ()
        ),
        "|"
    )

You will have to slightly modify the code to ensure that blanks and delimiters are added correctly.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

@amitchandak @Anonymous Thank you very much both the solution works with a little bit tweeking. Really appriciate your help.

Anonymous
Not applicable

You may use this approach.

 

ProxyUserName =
tableA[PathUsername]
    & CONCATENATEX (
        tableB,
        IF (
            NOT (
                ISBLANK ( SEARCH ( tableB[SearchString], tableA[PathUsername], 1, BLANK () ) )
            ),
            tableB[AddString],
            BLANK ()
        ),
        "|"
    )

You will have to slightly modify the code to ensure that blanks and delimiters are added correctly.

amitchandak
Super User
Super User

@Anonymous , Try like

concatenatex(filter(tableB, containsstring(tableA[PathUsername], tableB[SearchString])),tableB[AddString],"|")

Anonymous
Not applicable

@amitchandak 

 

I didn't knew that DAX has a function called CONTAINSSTRING. I just checked and found that there are few CONTAINS functions like CONTAINS, CONTAINSROW, CONTAINSTRING, CONTAINSTRINGEXACT, PATHCONTAINS. 
Are these new functions added recently? 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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