title: TSQL Count Case When In
body: <p>I am having trouble with some logic here. Trying to get a count of rows where S.ID's not in my subquery.</p>
  
  <pre><code>COUNT(CASE WHEN S.ID IN
  (SELECT DISTINCT S.ID FROM...) 
  THEN 1 ELSE 0 END)
  </code></pre>
  
  <p>I am recieving the error:</p>
  
  <pre><code>Cannot perform an aggregate function on an expression containing an aggregate or a subquery.
  </code></pre>
  
  <p>How to fix this or an alternative?</p>