Get unique values of a type attribute and count them WITH FILTERING

Yeah, that error message is not too helpful. There’s a syntax error in your query with A as distinctBrands.

I’m not picking up exactly what you’re laying down, but maybe a query like this might get you going in the right direction:

{
 	ITEMS as var(func: gt(Stem.weight, 39))
  
	q(func: uid(ITEMS)) @groupby(Stem.brand) {
		  count(uid)
	} 
}