title: Calculated field to select column based in countd in tableau
body: <p>I am trying to create a calculated field like the below.</p>
  
  <p>but it gives me an <strong>error on aggregate and non aggregate values</strong>.</p>
  
  <p>Can someone help?</p>
  
  <pre><code> if (COUNTD([Category])=1 then [Sub-Category]
  else [Category] END
  </code></pre>
  
  <blockquote>
    <p>Note: I am using the super store data. So when a user selects a filter
    in the quick filter for category, I was hoping that the countd becomes
    one and shows sub category as rows in the table instead of category.</p>
  </blockquote>