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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Lookup value that contains substring from another table

Hello,

 

I have table 1 that has a bunch of addresses

 

AddressValue
St George Street 12.....
5th Avenue South 3A......

      

I have table 2 that has a bunch of street names and their zip codes:

Street nameZip Code
St George Street32025

 

I want to create a new column in Table 1 with the Zip code from Table 2. How can I achieve this?

 

Thank you in advance!

1 ACCEPTED SOLUTION
ImkeF
Super User
Super User

Hi @Anonymous ,

you can add a column with the following formula:

 

Table.SelectRows(Table2, (x) => Text.Contains([Address], x[Street name])){0}[Zip Code]

This will return the first match, if there is any. Otherwise error. Just add some error-handling or remove errors afterwards.

For performance reasons, make sure to buffer Table2.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

7 REPLIES 7
v-yingjl
Community Support
Community Support

Hi @Anonymous ,

Basically the query mentioned by @ ImkeF should work, or you can try to use fuzzy merge:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCi5RcE/NL0pPVQguKUpNLVEwNFLSUTI0VYrViVYyLclQcCxLzSsFyuaXAjnGjkBJUwOwJKZOU6CkEVBnLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Address = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Address", type text}, {"Value", Int64.Type}}),
    #"Merged Queries" = Table.FuzzyNestedJoin(#"Changed Type", {"Address"}, #"Table 2", {"Street name"}, "Table 2", JoinKind.LeftOuter, [IgnoreCase=true, IgnoreSpace=true]),
    #"Expanded Table 2" = Table.ExpandTableColumn(#"Merged Queries", "Table 2", {"Zip Code"}, {"Zip Code"})
in
    #"Expanded Table 2"

m.png

Refer:

  1. Fuzzy Matching in Power BI / Power Query 
  2. Create a fuzzy match (Power Query) 

 

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

Anonymous
Not applicable

Hello,

 

I have tried Fuzzy Matching but it does not match that well. However I have tried to do this in DAX and it has worked for me 🙂 

ImkeF
Super User
Super User

Hi @Anonymous ,

you can add a column with the following formula:

 

Table.SelectRows(Table2, (x) => Text.Contains([Address], x[Street name])){0}[Zip Code]

This will return the first match, if there is any. Otherwise error. Just add some error-handling or remove errors afterwards.

For performance reasons, make sure to buffer Table2.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

Hi @ImkeF 

 

Thank you very much for your reply. However I got the error: 
Expression.Error: There weren't enough elements in the enumeration to complete the operation.

When I added the code as a custom column. Is there any way to fix this?

Hi @phuogh ,

it worked for me on my sample data. So there is a good chance that you didn't apply it correctly.
Please share our full code or the file for me to check.

 

Hi @Anonymous ,

it worked for me on my sample data. So there is a good chance that you didn't apply it correctly.
Please share our full code or the file for me to check.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

Hello,

 

Thank you for your help. After a while I tried to work around with DAX and it has worked for me 🙂 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors