Forum Discussion

Ironpixel's avatar
Ironpixel
Icon for Microsoft Employee rankMicrosoft Employee
5 years ago
Solved

Merge 2 tables using similar data to match

The title may be strange, but the essence will hopefully become clear. I am using Power BI - Tranform Data so Power Query   I have two tables: Table 1 User Name Team Number John /13575/6...
  • amitchandak's avatar
    5 years ago

    Ironpixel , Try a new column in Dax Like this

    maxx(filter(Table2, search(table2[Team Number], table1[eam Number],,0)>0),Table2[Team Name])

  • CNENFRNL's avatar
    5 years ago

    Hi, Ironpixel , you might want to try such a solution,

    let
        Lookup = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fc47CoAwEATQq8jWgSXsN6W/G9iFFBaW3r81opIiYDcMj2Fyhu3Yz2GEABhJTFBdiB09aYoEJbxi6kQkV25gfoCJfUDZqWYmxaRO1uzSj3kVdyXa2Po3SV4PQCkX", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Team Name" = _t, #"Team Number" = _t]),
    
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fcuxCgJBDIThd0l9EMIk2dnWwsJXWLY7wYPjBN+/MJ7Y2gQy/N8Ycns+DllEDdFCkwGnsmc3KJiEZhCuXk/KXIZcX/f1K1q0n0j/lHSk9kJNYQTPe6LLtu//EGiVOyzZa4JVWZPM+QY=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"User Name" = _t, #"Team Number" = _t]),
    
        Matchup = Table.AddColumn(
            Source, "Team Name",
            each List.Accumulate(
                Table.ToRecords(Lookup),
                {[Team Number], {}},
                (s, c) => if Text.Contains(s{0}, c[Team Number], Comparer.OrdinalIgnoreCase) then {s{0}, s{1}&{c[Team Name]}} else s
            ){1}
        ),
        #"Expanded Team Name" = Table.ExpandListColumn(Matchup, "Team Name")
    in
        #"Expanded Team Name"