If you have access to the new excel formulas FILTER
& UNIQUE
then:
=COUNTA(UNIQUE(FILTER(B2:B7,A2:A7=D2)))
If you don't have access to those formulas then you can use an array formula which must be confirmed with CTRL + SHIFT + ENTER
=SUM(--(FREQUENCY(IF(A2:A7=D3,MATCH(B2:B7,B2:B7,0)),ROW(B2:B7)-ROW(B2)+1)>0))
Image to relate equations to relevant ranges
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…