title: PowerBI DAX function to count number of occurrences using DISTINCT (Countif)
body: <p>I am trying to create a column in PowerBI that counts how times a customer name occurs in a list.</p>
  
  <p>I may be going in the wrong direction, but what I have so far is;</p>
  
  <p>My SQL query returns a table of customer site visits (<em>Query1</em>), from which I have created a new table (<em>Unique</em>) and column (<em>Customer</em>) that lists the distinct names (<em>cust_company_descr</em>) from <em>Query1</em>;</p>
  
  <blockquote>
    <p>Unique = DISTINCT(Query1[cust_company_descr])</p>
  </blockquote>
  
  <p>What I need is a new column in the <em>Unique</em> table (<em>Count</em>) that will give me a count of how many times each customer name in the <em>Query1</em> table appears.</p>
  
  <p>If I were working in Excel, the solution would be to generate a list of unique values and do a COUNTIF, but I can't find a way to replicate this.</p>
  
  <hr>
  
  <p>I have seen a few solutions that involve this sort of thing;</p>
  
  <blockquote>
    <p>CountValues =
    CALCULATE ( COUNTROWS ( TableName ); TableName[ColumnName] = " This Value " )</p>
  </blockquote>
  
  <p>The issue I have with this is the <em>Unique</em> table contains over 300 unique entries, so I can't make this work.</p>
  
  <hr>
  
  <p>Example (The <strong>Count</strong> column is what I'm trying to create)</p>
  
  <p><em>Query 1</em><br>
  <strong>cust_company_descr</strong><br>
  Company A<br>
  Company B<br>
  Company A<br>
  Company C<br>
  Company B<br>
  Company A  </p>
  
  <p><em>Unique</em><br>
  <strong>Company</strong>_____<strong>Count</strong><br>
  Company A_____3<br>
  Company B_____2<br>
  Company C_____1  </p>
  
  <p>Any help is gratefully received.</p>