google-sheetscomplement

Google spreadsheet get complements


Link here to spreadsheet

As the title says, how can I end up with cells that don't match in value, the difference/complement (set theory)?

I would prefer it with only FUNCTIONS and no script.

{1,2,3,4}\{1,3} = {2, 4}

or with letters

{a,b,c,d}\{a,c} = {b, d}

or with with space.

{xyz zyx, abc cba, qwe ewq}\{xyz zyx, qwe ewq} = {abc cba}

Solution

  • Having two arrays:

    Array1  Array2
      1       1
      2       b
      b 
      4 
      c 
    

    you can get resulting array:

    Result
      2
      4
      c
    

    Try this formula:

    =FILTER(A2:A6,ROUND(MMULT(ArrayFormula(--(A2:A6<>TRANSPOSE(B2:B4))),TRANSPOSE(SPLIT(REPT(1/ROWS(B2:B4)&"/",Rows(B2:B4)),"/"))),5)=1)
    

    May be too complex for this task, could somebody edit it? Please, look at sample sheet


    Edit

    I've found more simple way to do this, using Regular Expressions:

    =FILTER(A2:A6,REGEXMATCH(ARRAYFORMULA("'"&A2:A6),JOIN("|",B2:B3))=false)