=hstack(filter(A2:B,C2:C="Y")
,arrayformula(sumif(B2:B,tocol(unique(B2:B),1),D2:D)))
works.

------------
What we did was 2 parts: 1) filter PERSON, TEAM block by Lookup column; 2) aggregate COUNT column by TEAM column.
We can achieve either part with any number of methods. But to simplify the combining of the 2 parts, we should ideally preserve the same ordering in their outputs.
In the above example, filter and unique both result in the same ordering of outputs, which is the order of appearance in the original column. sumif re-uses the ordering from unique and thus the two parts have the same ordering. And combining is thus simply hstack.
tocol(_,1) use is required because unique includes blank cells.
-------------
Above is assuming the Lookup column is "clean": each Team only has 1 corresponding Lookup = "Y", which is the example used in OP. If the column is not clean, we would have multiple PERSONs passing the Lookup="Y" filter. In that case, a further _lookup (as in a function call of sort, to be distinct from OP's Lookup column) is required at the combining stage. Alternatively, we can process the data so it is clean. In the example below, we combine the cleaning and filtering by Lookup="Y" together in order to arrive at a convenient call of vlookup.
For example, we can replace the naive filter by Lookup="Y", which was
filter(A2:B,C2:C="Y")
with
let(selected,filter({B2:C,A2:B},C2:C="Y")
,uni,unique(choosecols(selected,1,2))
,arrayformula(vlookup(choosecols(uni,1),selected,{3,4})))
where we first filter data columns by Lookup = "Y", then select unique combination of TEAM and Lookup, and at the end, for each of such unique combination, we use vlookup to query the first occurrence of PERSON which passed the earlier filter.
The aggregate summation and the simple combining by hstack would remain unchanged. For clarity, the full formula would be
=let(selected,filter({B2:C,A2:B},C2:C="Y")
,uni,unique(choosecols(selected,1,2))
,arrayformula(hstack(vlookup(choosecols(uni,1),selected,{3,4})
,sumif(B2:B,tocol(unique(B2:B),1),D2:D))))
Alternatively, we can also note that unique TEAM + Lookup="Y" actually implies unique TEAM because the Lookup column only has 1 value after filter. That saves a unique call as follows, which can be advantageous for a large database.
=let(selected,filter({B2:C,A2:B},C2:C="Y")
,uni,wraprows(tocol(unique(choosecols(selected,1,2)),1),2)
,arrayformula(hstack(vlookup(choosecols(uni,1),selected,{3,4})
,sumif(B2:B,choosecols(uni,1),D2:D))))
Note that we chose hstack as a function call as opposed to {} so we do not have to balance the brackets manually at the end.
=QUERY(A2:D10, "SELECT A, B, SUM(D) WHERE C = 'Y' GROUP BY A, B")to see if that works? The QUERY function has aWHEREcondition that could GROUP BY TEAM, SUM COUNT, and match that back to PERSON WHERE LOOKUP is equal to Y.COUNTvalue forPERSONWHERELOOKUPis equal toY. I need the to return the SUM ofTEAMforPERSONWHERELOOKUPis equal toYas stated in the OP.=ARRAYFORMULA({FILTER(A2:B, C2:C = "Y"), SUMIF(B2:B, FILTER(B2:B, C2:C="Y"), D2:D)})work with what you'd like to do?