Forum Discussion

WillianLopes's avatar
WillianLopes
New Member
3 years ago
Solved

How to merge 2 tables in PowerQuery using substrings?

I have a sold items table. In this list, in addition to the name of the product, there are other expressions required by law - all on a single line.   In the second table I have the name of the pro...
  • WillianLopes's avatar
    3 years ago

    On another site I was given a great solution that I will share here to document.

     

    First add a custom column:

    Table.SelectRows(Table2, (x)=> Text.Contains ([Sold items], x[Products], Comparer.OrdinalIgnoreCase) )

     

    Now, expand the column.

    The code will be:

    let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Sold items", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Table.SelectRows(Table2, (x)=> Text.Contains ([Sold items], x[Products], Comparer.OrdinalIgnoreCase) )),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Products"}, {"Products"})
    in
    #"Expanded Custom"