title: Distinct cumulative count - PowerPivot, calculated fields and DAX
body: <p>I have struggled with this problem:
  <a href="https://stackoverflow.com/questions/34852566/pivot-chart-cumulative-running-in-distinct-count/34877872#34877872">Pivot chart cumulative (running in) distinct count</a></p>
  
  <p>I am copying it here for convenience...</p>
  
  <p>The idea was to create a cumulative distinct count using this data set:</p>
  
  <pre><code>Month ¦ Drink brand ¦ Drink type
  --------------------------------
  1     ¦ Abc         ¦ Water
  1     ¦ Def         ¦ Soft
  1     ¦ Abc         ¦ Water
  1     ¦ Ghi         ¦ Soft
  1     ¦ Xyz         ¦ Water
  2     ¦ Abc         ¦ Water
  2     ¦ Abc         ¦ Water
  2     ¦ Jkl         ¦ Soft
  2     ¦ Opq         ¦ Soft
  2     ¦ Abc         ¦ Water
  </code></pre>
  
  <p>And the required chart:</p>
  
  <pre><code>           ¦
  Drink      ¦
  type       ¦            S
  cumulative ¦            []
  unique     ¦ W  S    W  []
  count      ¦ [] []   [] []
             ¦_[]_[]___[]_[]_
                 1       2
                   Month
  </code></pre>
  
  <p>I have managed to solve the problem by using PowerPivot and DAX (Data Analysis Expressions) by creating two calculated fields. For "Water" it has been:</p>
  
  <pre><code>=CALCULATE (
      DISTINCTCOUNT( Range[Drink brand] ),
      FILTER (
          ALL ( Range[Month] ),
          Range[Month] &lt;= MAX ( Range[Month] )
      ),
      FILTER (
          ALL ( Range[Drink type] ),
          Range[Drink type] = "Water"
      )
  )
  </code></pre>
  
  <p>The problem I have with this solution is its low scallability (the need to create as many new calculated fields as there are "Drink types"). Is there a way to create the same result using DAX with just one calculated field or similar freature? Is is possible to group the result by "Drink type" in just one expression?</p>