Search code examples
google-sheetsfiltergoogle-sheets-formulacountinggoogle-sheets-query

COUNTIFS for Last 10 Matching Entries


Spreadsheet

Tab Ladder - Col J has a COUNTIFS formula that calculates % of matching criteria within the last 24hrs. I would like to limit the calculation to the last 10 matching entries within the 24hr window.

I have a stub formula in J35 outlining how I would like it structured. I have done a lot of searching, and while I have found a few examples of "Last x rows" - I haven't been able to translate those concepts to my specific needs.

Thank you in advance for your help!


Solution

  • instead of your:

    =COUNTIFS($A$18:$A, ">"&Dates!$C$4+TIME(Dates!$C$3,0,0)-1,
              $D$18:$D, $D35,
              $H$18:$H, $H35,
              $Y$18:$Y, "")
    

    use:

    =COUNTA(IFERROR(QUERY(FILTER(ROW($A$18:$A), 
     $A$18:$A>Dates!$C$4+TIME(Dates!$C$3,0,0)-1,
     $D$18:$D=$D35,
     $H$18:$H=$H35,
     $Y$18:$Y=""), "limit 10")))