if-statementgoogle-sheetsfiltergoogle-sheets-formulanested-if

Filter in Google Sheets not working within IF statement mismatched range sizes


I am receiving the following error:

FILTER has mismatched range sizes. Expected row count: 1759. column count: 1. Actual row count: 1, column count: 1.

The function in question is:

=IF(F2="",
    "Please enter a year",
    IF(F4="",
       IF(F6="",
          {"Same filter that built SrcTbl"},
          FILTER(SrcTbl,SrcCat=F6)),
       IF(F6="",
          FILTER(SrcTbl,MONTH(SrcDates)=MONTH(F4&1)),
          FILTER(SrcTbl,MONTH(SrcDates)=MONTH(F4&1),SrcCat=F6))))

SrcCat is a column within SrcTbl (e.g. A:A vs. A:C). The cells being checked contain a Year, a Month (or no month), and a Category (or no category). All of the filter functions work properly on their own, provided the respective cells are populated, and the function works properly if I replace the faulty filters (both containing SrcCat=F6) with a text string. It is only when a value is placed in F6 that the nested filters return this error.

Why do these filters work on their own, but not when inside this function?


Solution

  • instead of your:

    ={FILTER(CData,  YEAR(CDates) =B1);
      FILTER(SData,  YEAR(SDates) =B1);
      FILTER(CrData, YEAR(CrDates)=B1)}
    

    you can do just:

    =FILTER({CData; SData; CrData}, YEAR({CDates; SDates; CrDates})=B1)
    

    now what went wrong:

    enter image description here