Forum Discussion

Dicken's avatar
Dicken
Icon for Post Prodigy rankPost Prodigy
1 year ago
Solved

Power Query; List Remove / Matching Item

Hi, 
Can someone tell me if there is any practtical difference between  List.RemvoveItems and RemoveMatchinItems; 

example ; 

 

= [
alist = {"a","a","b","c","d","d","d","e","e","f","g"} ,
blist = { "a","d","e"} ,
matchitem = List.RemoveMatchingItems( alist, blist) ,
removeitem = List.RemoveItems( alist , blist )
]

I can't see that this is, i have seen things saying they treat duplicates differently but I can't get a reslt to show  this out? 

Richad. 

  • List.RemoveMatchingItems is more flexible as it allows you to override the matching criteria.

8 Replies

  • List.RemoveMatchingItems is more flexible as it allows you to override the matching criteria.

    • Dicken's avatar
      Dicken
      Icon for Post Prodigy rankPost Prodigy

      When you say override, could you give an example as I'm not sure what you mean unless 
      you mean the equation criteria, ? 
      Also is there a way to remove just a specifice number of items so if I have { "a","a","a","b","c"} 
      and just wanted to remvoe 1 "a"?  I am working on this so If succeed I will show . 

    • Dicken's avatar
      Dicken
      Icon for Post Prodigy rankPost Prodigy

      re remvoe one only ; I have come up with ; 

      let alist = {"a".."d","g","f","d","d","f","g","e"} ,

      val = {"d","f","g"} ,

      pos = List.Accumulate( val , {}, (s,c)=> s & { List.PositionOf( alist , c )} ),

      newpos = List.Difference( {0..List.Count( alist)-1 } , pos )

      in
      List.Transform( newpos, (x)=> alist {x} )

      I don't think I needed accumulate, as it lookslike there's and occurrnce first.