Forum Discussion

ValeriaBreve's avatar
ValeriaBreve
Post Partisan
3 years ago
Solved

Remove duplicates

Hello,

I have a table as per below. I need to remove duplicates so that one number of PO stays with each couple VBELN/POS, it does not really matter in which order.

I imagine this need sto be recursive, I am still not very proficient with it.... I appreciate your help!

 

Kind regards

Valeria

 

VBELNPOSPO
8000110123456
8000220123456
8000110654321
8000220654321
   
Result:  
   
VBELNPOSPO
8000110123456
8000220654321
  • AlienSx's avatar
    AlienSx
    3 years ago

    Hi, ValeriaBreve this works on your test data but I am not sure about real life data...

     

    let
        Source = your_table,
        groups = Table.Group(Source, {"PO"}, {{"VP", each List.Zip({[VBELN], [POS]})}}),
        lst = List.Buffer(groups[VP]),
        vp_txf = 
            List.Accumulate(
                lst,
                {},
                (s, c) => [a = List.Difference(c, s), b = s & {List.First(a)}][b]
            ),
        z = Table.FromColumns({groups[PO], vp_txf}, {"PO", "VP"}),
        extract = Table.TransformColumns(z, {"VP", each Text.Combine(List.Transform(_, Text.From), "@@@"), type text}),
        split = Table.SplitColumn(extract, "VP", Splitter.SplitTextByDelimiter("@@@", QuoteStyle.Csv), {"VBELN", "POS"})
    in
        split

     

15 Replies

    • ray_aramburo's avatar
      ray_aramburo
      Super User

      All of the lines these lines are unique considering that for each PO they have a different VBELN and POS in each row.

      VBELNPOSPO
      8000110123456
      8000220123456
      8000110654321
      8000220654321

       

      If you are expecting as a result 

      VBELNPOSPO
      8000110123456
      8000220654321

       

      What is your expectation for

      VBELNPOSPO
      8000220123456
      8000110654321

       

      • ValeriaBreve's avatar
        ValeriaBreve
        Post Partisan

        Hello ray_aramburo , I understand your confusion, I made a mistake in the mock data!!!! Sorry about it. This is how it should look:

         

        VBELNPOSPO
        8000110123456
        8000120123456
        8000110654321
        8000120654321
           
        Result:  
           
        VBELNPOSPO
        8000110123456
        8000120654321

         

        And then it does not matter which PO goes to which POS, as long as there is one PO only for each POS and that they are unique.

         

        Thanks!