title: Count Distinct with PostgreSQL
body: <p>I am trying to change the count DISTINCT portion of the query below, because the current query returns WINDOW definition is not supported.  What is most seamless way to do this calc using PostgreSQL?  Thank you.</p>
  
  <pre><code>SELECT transaction_date, brand, Description, Amount, newval
  into temp.table
  FROM (SELECT transaction_date, brand, Description, Amount,
           (Amount / count(DISTINCT unique_mem_id) over (partition by to_char(transaction_date, 'YYYY-MM'),brand
           )) as newval
    FROM source.table
   )
  WHERE DESCRIPTION iLIKE '%Criteria%';
  </code></pre>