Search code examples
excelexcel-formulaspreadsheet

How can I use COUNTIF and FILTER functions to get a count for the output array?


I have used this function to get how many times a specific input occurred in 3 shifts "M, E and N"

=COUNTA(FILTER(FILTER(Input!$D$3:$E$95,(Input!$D$3:$D$95=Nurses!A2)*(Input!$E$3:$E$95="E")),{0,1}))

So basically, I got the result as 4 when using COUNTA however if the FILTER gives and ERROR message, It turns that COUNTA considers it as a value of 1 which is absolutely not the fact.

I tried to replace COUNTA with COUNTIF

=COUNTIF(FILTER(FILTER(Input!$D$3:$E$95,(Input!$D$3:$D$95=Nurses!A2)*(Input!$E$3:$E$95="E")),{0,1}),"E")

the whole function doesn't run and I keep getting an Error message.

I decided to used IFERROR and IF

=IF(IFERROR(FILTER(FILTER(Input!$D$3:$E$95,(Input!$D$3:$D$95=Nurses!A2)*(Input!$E$3:$E$95="E")),{0,1}),0)=0,0,COUNTA(FILTER(FILTER(Input!$D$3:$E$95,(Input!$D$3:$D$95=Nurses!A2)*(Input!$E$3:$E$95="E")),{0,1})))

The output was an array of 4 times the number of E appearance in the FILTER function.

I hope that someone can help with this simple issue, I am so thankful in adavnce.

I tried Filter, IFERROR, IF, COUNT, COUNTA, COUNTIF


Solution

  • You could use:

    =IFERROR(ROWS(FILTER(Input!$E$3:$E$95,(Input!$D$3:$D$95=Nurses!A2)*(Input!$E$3:$E$95="E"))),0)