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
Sonaa
Regular Visitor

Retrieve Row location from other table based on matches

Hi all. Your views or comments are really appreciated.

I have 2 tables. One - "A" table , it has a customer address (short format) and second table "B"- has address(long format). Because of data format issues, I wasn't able to do a like by like match. I developed a methodology to do fuzzy match. So, splitted the customer address column in "A" Table by spaces. So, I got 4 different columns containing the strings. And then I checked whether eg. Customer address.1 was found anywhere in second table's address column. If there was a match, it returned true or else false. Below add1 shows whether the string matched to "B" tabels address column or not.

 

What I want to achieve?

16767356995294577432643866416338.jpg

For better clarity of matched address, I want the column which shows that string(in first table- "A") got matched to which row in address column(second table "B").  Basically a row information to help understand the matches address as a whole.

Please help! @Ayushkumar, @Amit @ayush ... All

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

@Sonaa 
Please refer to attached sample file with the solution

1.png

Best Match Adress = 
VAR CurrentCustAdress = SUBSTITUTE ( TableA[Customer Address - Copy], ", ", " " )
VAR String1 = SUBSTITUTE ( SUBSTITUTE ( CurrentCustAdress, UNICHAR ( 10 ), " " ), ",", " " )
VAR Items1 = SUBSTITUTE ( String1, " ", "|" )
VAR Length1 = COALESCE ( PATHLENGTH ( Items1 ), 1 )
VAR T1 = GENERATESERIES ( 1, Length1, 1 )
VAR T2 = SELECTCOLUMNS ( T1, "@Item2", PATHITEM ( Items1, [Value] ) )
VAR T3 = VALUES ( TableB[Address] )
VAR T4 = 
    ADDCOLUMNS ( 
        T3, 
        "@CountMatch",
        VAR String2 = TableB[Address]
        VAR Items2 = SUBSTITUTE ( String2, " ", "|" )
        VAR Length2 = COALESCE ( PATHLENGTH ( Items2 ), 1 )
        VAR T5 = GENERATESERIES ( 1, Length2, 1 )
        VAR T6 = SELECTCOLUMNS ( T5, "@Item2", PATHITEM ( Items2, [Value] ) )
        VAR T7 = INTERSECT ( T2, T6 )
        RETURN
            COUNTROWS ( T7 )
    )
VAR T8 = TOPN ( 1, T4, [@CountMatch] )
RETURN
    MAXX ( T8, [Address] )

 

 

View solution in original post

10 REPLIES 10
tamerj1
Super User
Super User

@Sonaa 
Please refer to attached sample file with the solution

1.png

Best Match Adress = 
VAR CurrentCustAdress = SUBSTITUTE ( TableA[Customer Address - Copy], ", ", " " )
VAR String1 = SUBSTITUTE ( SUBSTITUTE ( CurrentCustAdress, UNICHAR ( 10 ), " " ), ",", " " )
VAR Items1 = SUBSTITUTE ( String1, " ", "|" )
VAR Length1 = COALESCE ( PATHLENGTH ( Items1 ), 1 )
VAR T1 = GENERATESERIES ( 1, Length1, 1 )
VAR T2 = SELECTCOLUMNS ( T1, "@Item2", PATHITEM ( Items1, [Value] ) )
VAR T3 = VALUES ( TableB[Address] )
VAR T4 = 
    ADDCOLUMNS ( 
        T3, 
        "@CountMatch",
        VAR String2 = TableB[Address]
        VAR Items2 = SUBSTITUTE ( String2, " ", "|" )
        VAR Length2 = COALESCE ( PATHLENGTH ( Items2 ), 1 )
        VAR T5 = GENERATESERIES ( 1, Length2, 1 )
        VAR T6 = SELECTCOLUMNS ( T5, "@Item2", PATHITEM ( Items2, [Value] ) )
        VAR T7 = INTERSECT ( T2, T6 )
        RETURN
            COUNTROWS ( T7 )
    )
VAR T8 = TOPN ( 1, T4, [@CountMatch] )
RETURN
    MAXX ( T8, [Address] )

 

 

Thanks alot tamerj1. That really helps!

tamerj1
Super User
Super User

Hi @Sonaa 

in other words you want to find the best match of table A short address from table B long address. Is that correct? The four columns that you're creating are just steps to obtain the desired result, roght? Can you please provide a dummy sample of both tables?

 Yes, I want to find the best match from table A( short address) to table B(long address). And 4 columns which I have created is in table A by splitting it by space delimeter. Like:- customer address.1 has sauchiel customer address.2 has street... And other columns..

So finding where sauchiel string is existing in table B's Address( full address column). 

 

I actually got that matching logic sorted using Text.Contain(Text.Combine( B[ Address], [customer address.1]). This gave me True or False , depending on its occurrence. 

 

Now, I just need to check that when sauchiel string came as true , which Address row from B table did it got matched?

 

 

 

 

Sonaa
Regular Visitor

IMG_20230218_213013.jpg

 this screenshot is of Table "B" having full address. And below one is of table "A" having short format/vague address, so splitted that into 4 columns by split by delimeter. 

IMG_20230218_214044.jpg

  •  Table B. Here add1,2,3,4 and postcode are the matches check, which gave True and False respectively.

Now need to find that if add1 came true, so where did it's customer address.1 matched in table B. 

Your early response would be really helpful as I am stucked on this since. Thanks!

 

Thank you @Sonaa for the explanation.
I can try to find a solution using DAX rather than Power Query. If ok with you please provide a copy/paste sample of data of both tables to work with.

    Spoiler
    Thanks @tamerj1 . Actually I am unable to upload the sample. Can you please try and frame the Dax query ? If so it would be really helpful.

@Sonaa 

You don't need to upload a file. If you already have a sample file you can upload to any file transfer service like OneDrive, DropBox or we transfer ans just share the download link. Otherwise, you can copy the tables and paste them as is in a comment or share a clear screenshot (not picture) of both tables. 
Such queries can be a bit complex and the DAX solution is not something that is obtained off-shelf. Sample data os require to create a proper workable solution 

Table B.PNG

 table B.

Table A.PNG

 table A

Table B (add 1 column to check whether match found).PNG

  •  table B( checking whether match is found)
Sonaa
Regular Visitor

Hi @tamerj1 . Yes, thanks. Have attached the screenshots. Due to some reasons, not able to upload my file here or on OneDrive. Hope this screenshots helps in getting things sorted soon.

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