Forum Discussion

mraka9's avatar
mraka9
Helper III
4 years ago
Solved

Linking related items within the same table-Power Query

I need help with Power Query.
I have a table with columns: A, B and C
Column A and C contain identical items to be linked.
I want column C to check where everything is in column A and show concatenated in column D.
I hope that is clear enough.
I did it by duplicating the tables and then merging them, but it's a complex query and consumes too many resources, so I'd like it all to be done in the same table.

Thanks in advance!

A

B

C

D

AAA

456

BBB

777;258

BBB

777

AAA

456;111

CCC

369

CCC

369;750

AAA

111

BBB

777;258

BBB

258

CCC

369;750

CCC

750

AAA

456;111

10 Replies

  • Hey mraka9 ,

    to create this

    I created an inline function using the advanced editor, the code below added the custom column "Custom", which holds the result, the combinedString:

    ...
        #"Added Custom" = 
            Table.AddColumn(#"Changed Type", "Custom", 
            ( row ) => 
                let
                filtervalue = row[C],
                combinedString = 
                    Text.Combine(
                        List.Transform(
                            Table.SelectRows( #"Changed Type" , each [C] = filtervalue )[B]
                            , each Number.ToText( _ )
                        )
                    , ";") 
                in
                combinedString
            )
    in
        #"Added Custom"


    Hopefully, this provides what you are looking for. If not, consider creating a pbix that contains sample data, upload the pbix to onedrive, googledrive, or dropbox and share the link. If you are using Excel to create the sample data share the xlsx as well.

    Regards,
    Tom

    • mraka9's avatar
      mraka9
      Helper III

      Unfortunately, the result is not correct. Column D should contain the items as shown in the example.
      Thanks anyway!

  • Hey mraka9 ,

     

    if you change this line

    Table.SelectRows( #"Changed Type" , each [C] = filtervalue )[B]

    to this

    Table.SelectRows( #"Changed Type" , each [A] = filtervalue )[B]

    the function returns what you are looking for:


    Regards,
    Tom