title: Inaccurate COUNT DISTINCT Aggregation with Date dimension in Google Data Studio
body: <p>When I aggregate values in Google Data Studio with a <em>date dimension</em> on a <strong>PostgreSQL Connector</strong>, I see buggy behaviour. The symptom is that performing <code>COUNT(DISTINCT)</code> returns the same value as <code>COUNT()</code>:</p>
  
  <p><a href="https://i.stack.imgur.com/Mt6Ve.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Mt6Ve.png" alt="incorrect count value for userid when connector is postgres"></a></p>
  
  <p>My theory is that it has something to do with the aggregation on the data occurring after the count has already happened. If I attempt the exact same aggregation on the same data in an exported <strong>CSV</strong> instead of directly from a <strong>PostgreSQL Connector</strong> <em>Data Source</em>, the issue does not reproduce:</p>
  
  <p><a href="https://i.stack.imgur.com/66qfS.png" rel="noreferrer"><img src="https://i.stack.imgur.com/66qfS.png" alt="correct count value for userid when connector is a csv file"></a></p>
  
  <p>My <strong><em>PostgreSQL Connector</em></strong> is connecting to <strong>Amazon Redshift</strong> (<code>jdbc:postgresql://*******.eu-west-1.redshift.amazonaws.com</code>) with the following custom query:</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT
    userid,
    submissionid,
    date
  FROM mytable
  </code></pre>
  
  <hr>
  
  <h2>Workaround</h2>
  
  <p>If I stop using the default <code>date</code> field for the <em>Date Dimension</em> and aggregate my own dates directly in within the SQL query (<code>date_byweek</code>), the <code>COUNT(DISTINCT)</code> aggregation works as expected:</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT
    userid,
    submissionid,
    to_char(date,'YYYY-IW') as date_byweek
  FROM mytable
  </code></pre>
  
  <p>While this workaround solves my immediate problem, it sucks because I miss out on all the date functionality provided by Data Studio (<em>Hierarchy Drill Down</em>, <em>Date Range filtering</em>, etc.). Not to mention reducing my confidence at what else may be "buggy" within the product </p>
  
  <hr>
  
  <h2>How to Reproduce</h2>
  
  <p>If you'd like to re-create the issue, using the following data as a <strong>PostgreSQL</strong> <em>Data Source</em> should suffice:</p>
  
  <pre><code>&gt; SELECT * FROM mytable
    userid  submissionid
  -------- -------------
         1             1
         2             2
         1             3
         1             4
         3             5
  
  &gt; COUNT(DISTINCT userid) -- ERROR:    Returns 5 when data source is PostgreSQL
  &gt; COUNT(DISTINCT userid) -- EXPECTED: Returns 3 when data source is CSV (exported from same PostgreSQL query above)
  </code></pre>