title: Conditional Distinct Count in Crystal Reports
body: <p>I have a dataset like this:</p>
  
  <pre><code>ID    PersonID    ClassID    Attended    Converted
  1     1           1          1           0
  2     1           1          1           1
  3     1           1          1           1
  4     2           1          1           1
  5     3           2          0           0
  6     3           2          1           1
  7     4           2          1           0
  </code></pre>
  
  <p>I'm building a report that groups by ClassID (actually I'm using a parameter that allows grouping on a few different cols, but for simplicity here, I'm just using ClassID). I need to do a calculation in each group footer. In order to do the calculation, I need to count records with PersonIDs unique to that group. The catch is, in one case, these records also need to match a criteria. EG:</p>
  
  <pre><code>X = [Count of records where Converted = 1 with distinct PersonID]
  Y = [Count of records where Attended = 1]
  </code></pre>
  
  <p>Then I need to display the quotient as a percentage:</p>
  
  <pre><code>(X/Y)*100
  </code></pre>
  
  <p>So the final report would look something like this:</p>
  
  <pre><code>ID    PersonID    Attended    Converted
  CLASS 1 GROUP
  1     1           1           0
  2     1           1           1
  3     1           1           1
  4     2           1           1
  
  Percent= 2/4 = 50%
  
  CLASS 2 GROUP
  5     3           0           0
  6     3           1           1
  7     4           1           0
  
  Percent= 1/2 = 50%
  </code></pre>
  
  <p>Notice in Class 1 Group, there are 3 records with Converted = 1 but 'X' (the numerator) is equal to 2 because of the duplicate PersonID. How can I calculate this in Crystal Reports?</p>