Google-sheets – How to filter Queried Data in an Array

google sheetsgoogle-sheets-arrayformulagoogle-sheets-filtergoogle-sheets-queryregex

Sample Spreadsheet: https://docs.google.com/spreadsheets/d/16p4M5UBODyBhmWFXYrA0FdLsA1FmwSmbrF12VUHlGaw/edit?usp=sharing

I have this formula which works great:

=ARRAYFORMULA(QUERY({Projects!A:C, (REGEXEXTRACT((RIGHT(Projects!C:C,LEN(Projects!C:C)-13)),"[\w]* [\w]*")), Projects!D:H},"SELECT Col1, Col4, Col7 WHERE LOWER(Col3) CONTAINS 'receive' AND LOWER(Col3) CONTAINS 'payment' AND Col9<>'Complete' AND Col9<>'N/A' ORDER BY Col7 ASC LIMIT 8 LABEL Col1 '', Col4 '', Col7 ''"))

I'm trying to show only the results where Projects!A:A (Col1) is within a range on another sheet.

Without the Array, typically I'd write it like this:

=QUERY(FILTER(Projects!A:C,MATCH(Projects!A:A,INDIRECT("'"&$D$2&"'!A:A"), 0)),"SELECT STATEMENT HERE")

When adding the FILTER(MATCH( into the first original working formula you get this:

=ARRAYFORMULA(QUERY({FILTER(Projects!A:C, MATCH(Projects!A:A,INDIRECT("'"&$D$2&"'!A:A"), 0)), (REGEXEXTRACT((RIGHT(Projects!C:C,LEN(Projects!C:C)-13)),"[\w]* [\w]*")), Projects!D:H},"SELECT Col1, Col4, Col7 WHERE LOWER(Col3) CONTAINS 'receive' AND LOWER(Col3) CONTAINS 'payment' AND Col9<>'Complete' AND Col9<>'N/A' ORDER BY Col7 ASC LIMIT 8 LABEL Col1 '', Col4 '', Col7 ''"))

The result is an error:

"Function ARRAY_ROW parameter 2 has mismatched row size. Expected: 2377. Actual: 6816."

The Projects tab is 6816 rows long, but I don't know what is 2377 rows long.

The interesting thing is that when I'm within the Formula bar, the schematic highlighting isn't working for parameter 2 of FILTER. See attached image.enter image description here

How can I add filter the results of Col1 to only show if the results are within another tab's range?

Best Answer

You can try the following formula instead

=ARRAYFORMULA(QUERY({Projects!A1:C44,REGEXEXTRACT(Projects!C1:C44,"\w+ Payment"), Projects!D1:H44}, 
"SELECT Col1, Col4, Col7 
 WHERE LOWER(Col3) CONTAINS 'receive' AND LOWER(Col3) CONTAINS 'payment' 
      AND Col9<>'Complete' and lower(Col5) contains '"&LOWER(REGEXEXTRACT('Report Helpers'!A1,"(\D+)'"))&"'
 ORDER BY Col7 ASC LIMIT 50 LABEL Col1 'Project', Col4 'Payment', Col7 'Estimated Due Date'"))

The above is based on your existing formula. There are simpler solutions as well if interested.