Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Lookup for each value in a delimited string

Hello,   I have a situation where I need to perform a lookup, but the search value column (Tester ID(s)) sometimes has more than one value that is pipe-delimited. In my example below, is it possibl...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Anonymous ,

    Consider also using M for this:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjYxqTExM1WK1YlWMjQ2NQYzjI1NagzNzSzMITwLS6XYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Tester ID(s)" = _t]),
        #"Added Custom" = Table.AddColumn(Source, "ID", each Text.Split([#"Tester ID(s)"], "|")),
        #"Expanded ID" = Table.ExpandListColumn(#"Added Custom", "ID"),
        #"Changed Type1" = Table.TransformColumnTypes(#"Expanded ID", {{"ID", Int64.Type}}),
        #"Merged Queries" = Table.NestedJoin(#"Changed Type1", {"ID"}, UserInfoTable, {"ID"}, "UserInfoTable", JoinKind.LeftOuter),
        #"Expanded UserInfoTable" = Table.ExpandTableColumn(#"Merged Queries", "UserInfoTable", {"Name"}, {"Name"}),
        #"Grouped Rows" = Table.Group(#"Expanded UserInfoTable", {"Tester ID(s)"}, {{"Matched Tester Name(s)", each Text.Combine([Name], ",")}})
    in
        #"Grouped Rows"

    A sample file is attached for reference.

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
    If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

  • dufoq3's avatar
    2 years ago

    Hi Anonymous, different approach:

     

    Result

    let
        TestersTable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjYxqTExM1WK1YlWMjQ2NQYzjI1NagzNzSzMITwLS6XYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Tester ID(s)" = _t]),
        UserInfoTable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjY2UdJRcspPUorVAfJMQLyQzFwIz8ISyPPKTwXzTMxMgbzgUgjP0NzMwhykM7WkpFIpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Name = _t]),
        BufferedUserInfo = Table.Buffer(UserInfoTable),
        Ad_MatchedTesterNames = Table.AddColumn(TestersTable, "Matched Tester Name(s)", each 
            [ a = Text.Split([#"Tester ID(s)"], "|"),
              b = List.Combine(List.Transform(a, (x)=> Table.SelectRows(BufferedUserInfo, (y)=> y[ID] = x)[Name])),
              c = if List.IsEmpty(b) then null else Text.Combine(b, ", ")
            ][c], type text)
    in
        Ad_MatchedTesterNames