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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
johnlhaase
Helper I
Helper I

Merge based on partial string sequence

Hello

 

I have two table with text number fields. One is the complete number and the other is an offset of the first meaning it could be text 3 through 13 or 2 through 12. A fuzzy merge does not return the correct information. So I would like either table A to return the partial match in table B or have table B return the partial match in A. Table B's number is a slightly different offset in each row. Again these are numbers stored as texts. Any way to do this match?

 

Table A

TicketNumber
01470614238450
01467031551686
01470655645513
01470680045763
Table B
7061423845
031551686
70655645513
7068004517
7068004515
92
3 ACCEPTED SOLUTIONS

yes, the proposed solution is based on Text.Contains.

 

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.

View solution in original post

ronrsnfld
Super User
Super User

Using List.FindText function to locate the correct full number for a partial number

TableA

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TcrBCcAwDAPAXfLuQ64l2buE7L9GTaHQ73F7LwQLDt7ZFNa5XnIhQwq3P5olmYP5owao8tB5AA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [TicketNumber = _t])
in
    Source

TableB

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VcuxDQAgCETRXagtQDjEWQj7r6HRWFi+f7lMGuxiXcNA1ZJYBRAPP9oj4LaLPgezQcbP+52dqhY=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [TicketNumber = _t]),
    
//Add the full ticket number if a match
    #"Added Custom" = Table.AddColumn(Source, "TicketNumberA", each List.FindText(TableA[TicketNumber],[TicketNumber]){0}?, type text),

//add the non-matching TableA numbers
    #"Add from TableA" = Table.Combine({#"Added Custom", 
        Table.SelectRows(Table.RenameColumns(TableA,{"TicketNumber", "TicketNumberA"}), 
        each not List.Contains(#"Added Custom"[TicketNumberA],[TicketNumberA]))
        })
in
    #"Add from TableA"

 

Result

ronrsnfld_0-1718417329767.png

 

 

View solution in original post

Anonymous
Not applicable

Hi,

Thanks for the solutions @ronrsnfld  and  @lbendlin  provided, and i  want to offer some more information for user to refer to,

hello @johnlhaase , you can refer to the following solution.

Table A

vxinruzhumsft_0-1718587984338.png

Table B

vxinruzhumsft_1-1718588002299.png

Then in table a create a custom column

let a=[TicketNumber]
in Text.Combine(List.Select(#"Table B"[Column1],each Text.Contains(a,_)),",")

Output

vxinruzhumsft_2-1718588091120.png

And you can refer to the attachments.

 

Best Regards!

Yolo Zhu

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
Anonymous
Not applicable

Hi,

Thanks for the solutions @ronrsnfld  and  @lbendlin  provided, and i  want to offer some more information for user to refer to,

hello @johnlhaase , you can refer to the following solution.

Table A

vxinruzhumsft_0-1718587984338.png

Table B

vxinruzhumsft_1-1718588002299.png

Then in table a create a custom column

let a=[TicketNumber]
in Text.Combine(List.Select(#"Table B"[Column1],each Text.Contains(a,_)),",")

Output

vxinruzhumsft_2-1718588091120.png

And you can refer to the attachments.

 

Best Regards!

Yolo Zhu

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

ronrsnfld
Super User
Super User

Using List.FindText function to locate the correct full number for a partial number

TableA

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TcrBCcAwDAPAXfLuQ64l2buE7L9GTaHQ73F7LwQLDt7ZFNa5XnIhQwq3P5olmYP5owao8tB5AA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [TicketNumber = _t])
in
    Source

TableB

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VcuxDQAgCETRXagtQDjEWQj7r6HRWFi+f7lMGuxiXcNA1ZJYBRAPP9oj4LaLPgezQcbP+52dqhY=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [TicketNumber = _t]),
    
//Add the full ticket number if a match
    #"Added Custom" = Table.AddColumn(Source, "TicketNumberA", each List.FindText(TableA[TicketNumber],[TicketNumber]){0}?, type text),

//add the non-matching TableA numbers
    #"Add from TableA" = Table.Combine({#"Added Custom", 
        Table.SelectRows(Table.RenameColumns(TableA,{"TicketNumber", "TicketNumberA"}), 
        each not List.Contains(#"Added Custom"[TicketNumberA],[TicketNumberA]))
        })
in
    #"Add from TableA"

 

Result

ronrsnfld_0-1718417329767.png

 

 

johnlhaase
Helper I
Helper I

Does a contain function work in this application?

yes, the proposed solution is based on Text.Contains.

 

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.

lbendlin
Super User
Super User

Table B

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VcuxDQAgCETRXagtQDjEWQj7r6HRWFi+f7lMGuxiXcNA1ZJYBRAPP9oj4LaLPgezQcbP+52dqhY=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Pattern = _t])
in
    Source

Table A

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TcrBCcAwDAPAXfLuQ64l2buE7L9GTaHQ73F7LwQLDt7ZFNa5XnIhQwq3P5olmYP5owao8tB5AA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [TicketNumber = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Match", (k)=> Table.SelectRows(#"Table B",each Text.Contains(k[TicketNumber],[Pattern]))),
    #"Expanded Match" = Table.ExpandTableColumn(#"Added Custom", "Match", {"Pattern"}, {"Pattern"})
in
    #"Expanded Match"

Hello

 

I understand M code a little and do not see where my soures data gets entered into the script. Could you explain it a little more?

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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