The following query is working:
SELECT ?goal (count(?ngo) as ?ngoCount)
WHERE {?ngo a ngo:NGORecipient;
ngo:hasSDGGoal ?goal.
?goal rdfs:label ?sdglabel.}
GROUP BY ?goal
ORDER BY ?ngoCount
However, when I go to get the label rather than the IRI as follows
SELECT ?sdglabel (count(?ngo) as ?ngoCount)
WHERE {?ngo a ngo:NGORecipient;
ngo:hasSDGGoal ?goal.
?goal rdfs:label ?sdglabel.}
GROUP BY ?goal
ORDER BY ?ngoCount
I get an error: "Executing query failed: All selected variables must be aggregates but ?sdglabel is not."