title: How to add total sum of each rows within group with DAX Power BI
body: <p>I am trying to give rank column of every group which repeating in every rows within the group of the original table but not the shape of after sum-up. </p>
  
  <p>The formula i found in another site but it show an error :
  <a href="https://intellipaat.com/community/9734/rank-categories-by-sum-power-bi" rel="nofollow noreferrer">https://intellipaat.com/community/9734/rank-categories-by-sum-power-bi</a></p>
  
  <p>Table1</p>
  
  <pre><code>+-----------+------------+-------+
  
  | product   | date       | sales |
  
  +-----------+------------+-------+
  
  | coffee    | 11/03/2019 | 15    |
  
  | coffee    | 12/03/2019 | 10    |
  
  | coffee    | 13/03/2019 | 28    |
  
  | coffee    | 14/03/2019 | 1     |
  
  | tea       | 11/03/2019 | 5     |
  
  | tea       | 12/03/2019 | 2     |
  
  | tea       | 13/03/2019 | 6     |
  
  | tea       | 14/03/2019 | 7     |
  
  | Chocolate | 11/03/2019 | 30    |
  
  | Chocolate | 11/03/2019 | 4     |
  
  | Chocolate | 11/03/2019 | 15    |
  
  | Chocolate | 11/03/2019 | 10    |
  
  +-----------+------------+-------+
  </code></pre>
  
  <p>The Goal</p>
  
  <pre><code>+-----------+------------+-------+-----+------+
  
  | product   | date       | sales | sum | rank |
  
  +-----------+------------+-------+-----+------+
  
  | coffee    | 11/03/2019 | 15    | 54  | 5    |
  
  | coffee    | 12/03/2019 | 10    | 54  | 5    |
  
  | coffee    | 13/03/2019 | 28    | 54  | 5    |
  
  | coffee    | 14/03/2019 | 1     | 54  | 5    |
  
  | tea       | 11/03/2019 | 5     | 20  | 9    |
  
  | tea       | 12/03/2019 | 2     | 20  | 9    |
  
  | tea       | 13/03/2019 | 6     | 20  | 9    |
  
  | tea       | 14/03/2019 | 7     | 20  | 9    |
  
  | Chocolate | 11/03/2019 | 30    | 59  | 1    |
  
  | Chocolate | 11/03/2019 | 4     | 59  | 1    |
  
  | Chocolate | 11/03/2019 | 15    | 59  | 1    |
  
  | Chocolate | 11/03/2019 | 10    | 59  | 1    |
  
  +-----------+------------+-------+-----+------+
  </code></pre>
  
  <p>The script </p>
  
  <pre><code>sum =
  
  SUMX(
  
      FILTER(
  
           Table1;
  
           Table1[product] = EARLIER(Table1[product])
  
      );
  
      Table1[sales]
  
  ) 
  </code></pre>
  
  <p>The Error :</p>
  
  <pre><code>EARLIER(Table1[product]) # Parameter is not correct type cannot find name 'product' 
  </code></pre>
  
  <p>What's wrong with the script above ?
  * not able to test this script: </p>
  
  <pre><code>rank = RANKX( ALL(Table1); Table1[sum]; ;; "Dense" )
  </code></pre>
  
  <p>before fixed the sum approach</p>