Or you may use IFERROR to exclude errors like this.....

=SUMPRODUCT(IFERROR(1/COUNTIF(G2:G2000,G2:G2000)*(J2:J2000=N2),0))
Don't forget to confirm it with Ctrl+Shift+Enter instead of just Enter as this is an Array Formula.

Does this help?