title: OData v4 groupby with $count
body: <p>I'm using OData v4 with WebAPI with these nuget-packages:</p>
  
  <p><a href="https://www.nuget.org/packages/Microsoft.Data.OData/5.7.0" rel="noreferrer">Microsoft.Data.OData 5.7.0</a></p>
  
  <p><a href="https://www.nuget.org/packages/Microsoft.AspNet.WebApi.OData/4.0.30506" rel="noreferrer">Microsoft.AspNet.WebApi.OData 4.0.30506</a> </p>
  
  <p>I can't get <code>groupby</code> to work with count. It should be the most simple thing.</p>
  
  <p>I have a simple table/entity called <code>Delivery</code>. It has a status column (among several other ones). What I basically want to do is this SQL query, but with OData:</p>
  
  <pre><code>SELECT e.status, count(*) AS total
  FROM Delivery e
  GROUP BY e.status
  </code></pre>
  
  <p>I've tried using <a href="http://docs.oasis-open.org/odata/odata-data-aggregation-ext/v4.0/cs01/odata-data-aggregation-ext-v4.0-cs01.html#_Standard_Aggregation_Method" rel="noreferrer"><code>countdistinct</code></a>, but it doesn't give me the correct results.</p>
  
  <pre><code>/odata/deliveries?$apply=groupby((status),aggregate(status with countdistinct as total))
  </code></pre>
  
  <p>It returns:</p>
  
  <pre><code>"value": [
  {
      "@odata.id": null,
      "total": 1,
      "status": 1
  },
  {
      "@odata.id": null,
      "status": 2,
      "total": 1
  },
  {
      "@odata.id": null,
      "status": 4,
      "total": 1
  }
  ]
  </code></pre>
  
  <p>The correct results should be (which is what my SQL-query returns):</p>
  
  <pre><code>status  total
  1       2
  2       22
  4       1
  </code></pre>
  
  <p>I've also read about the virtual property <a href="http://docs.oasis-open.org/odata/odata-data-aggregation-ext/v4.0/csprd01/odata-data-aggregation-ext-v4.0-csprd01.html#_The_Virtual_Property" rel="noreferrer"><code>$count</code></a>, but it seems as Microsoft <a href="https://github.com/OData/WebApi/issues/773" rel="noreferrer">doesn't support it yet</a>.</p>
  
  <p><strong>How do I use <code>group by</code> together with a simple <code>count</code> with OData v4?</strong></p>