matrices – How to count unique occurrences with criteria in Excel

I am using the following matrix formula to count the unique occurrences of text in column C using the name of the agent in column G as a reference. This is giving me multiple problems.

= SUM (- (FREQUENCY (IF (G3: G100000 = J5, MATCH (C3: C100000, C3: C100000,0)), ROW (C3: C100000) – ROW (C3) + 1)> 0))

1) Depending on the data set I am using, the agents will return a result of # N / A and I can not understand why.
2) Each set of data that I am using is from 20k to 30k lines, so the formulas take a long time to process.

Any idea how I could do this faster or better? Also some idea of ​​why some agents get bad returns?