This function will ensure that GROUP BY is always before ORDER BY unfortunatly the SPARQL builder does not ensure this, but it might be fixed upstream in the future