Using groupby in hook_views_query_alter()
"Group By" is not working on hook_views_query_alter and it is views module issue. that is reported at https://drupal.org/node/590534, http://drupal.org/node/1608742, http://drupal.org/node/389230#comment-2637200

So, You should use other hooks such as general hook_query_alter.

function hook_query_alter( &amp;$query) {

  if($query-&gt;alterMetaData['view']-&gt;name == "your_views_name"){
     $query-&gt;groupBy("domain_source.domain_id");
     //also you can unset other group by critera by using, unset($query-&gt;getGroupBy());
  }
}