Excel: Using "And" condition comparing derived values -


i have spread sheet has multiple divisions going down in rows, each row has 1 person , relevant information employees. have used formula eliminate duplicate divisions. trying create summary information divisions.

my division consolidated formula =index($f$2:$f$587,match(0,countif($j$1:j1,$f$2:$f$587),0))

now use derived value corresponding cell j2:j21 , count row if value in f2:f588 equal value in j cell , value in h2:h588 equal value in q1

this goal count how many persons in organization amind , total place total number in division.. have tried number or permutation cannot seem work.
enter image description here

if understood question correctly want is:
(1) unique values of column f listed in column j
(2) first want match column f values in column j
(3) match corresponding column h values cells n1, o1, p1, q1, ....
(4) (2) , (3) conditions count under cells n1, o1, p1, q1, ....

if understanding correct enter following formula in cell n1:

=countifs($f$2:$f$587,$j2,$h$2:$h$587,n$1) 

and drag/copy formula across , down required.

see image below (with data till row 25):

enter image description here