Search code examples
google-sheetsarray-formulas

FILTER ARRAYFORMULA with Dynamic Criteria


Here's my data.

[C]                 [D]        [E]  [F]                 [G]
Timestamp           Submitter  Year Song                Artist
11/15/2020 8:42:57  A          2005 Feel Good, Inc.     Gorillaz
11/16/2020 19:08:13 B          2005 Feel Good, Inc.     Gorillaz
11/15/2020 9:33:01  C          2005 The Hand That Feeds Nine Inch Nails
11/15/2020 19:59:22 D          2005 The Hand That Feeds Nine Inch Nails

Here's what I'm trying to do. Basically, I need to pull the timestamp from the 2nd time someone submitted a song. Seems like it should be doable, but the code below only produces a single row. Is there a way to make this work properly as an array formula?

=ARRAYFORMULA( SMALL( FILTER( C2:C, E2:E & F2:F & G2:G = E2:E & F2:F & G2:G), 2) )

Solution

  • Sorry, this was much easier than I was imagining. I just needed a helper column in Column C to count up the instances of the song, like so:

    =ARRAYFORMULA(IF(F2:F<>"",COUNTIFS(F2:F&G2:G&H2:H,F2:F&G2:G&H2:H,ROW(F2:F),"<="&ROW(F2:F)),""))
    

    ...then an ARRAYFORMULA(VLOOKUP()) to pull the 2nd timestamp value for each song:

    =ARRAYFORMULA(IF(G2:G<>"",VLOOKUP(F2:F&G2:G&H2:H&2,{F2:F&G2:G&H2:H&C2:C,D2:D},2,0),""))
    

    Not sure how it could have been done in one go, though, so if you know a way, please do chime in.