cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
phuogh
Helper II
Helper II

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 II
Super User II

Hi @phuogh ,

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 @phuogh ,

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.

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 II
Super User II

Hi @phuogh ,

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

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 @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.

 

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

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
PBI_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Get Ready for Power BI Dev Camp

Microsoft named a Leader in The Forrester Wave

Microsoft received the highest score of any vendor in both the strategy and current offering categories.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Top Kudoed Authors