title: Custom column adding to the matrix power bi like diff , total , avg
body: <p>I have a input like below</p>
  <pre><code>Name WK pirce 
  AA   1   10
  BB   2   20
  CC   3   30
  DD   4   20
  AA   4   10
  BB   4   20
  </code></pre>
  <p>I would like to calculate see the weeks in rows and last week difference &amp; the last - past 3 wk value</p>
  <p>so i have created a measure as below</p>
  <pre><code>   Total = SUM('Table'[Price])
  </code></pre>
  <p>for last week difference</p>
  <pre><code>Difference = 
  var LWK=CALCULATE(MAX('Table'[WK]),all('Table'))
  Var BLWK=CALCULATE(MAX('Table'[WK])-1,all('Table'))
  var D1=CALCULATE([Total],'Table'[WK]=LWK)
  var D2=CALCULATE([Total],'Table'[WK]=BLWK)
  return
  IF(ISINSCOPE('Table'[WK]),SUM('Table'[Price]),D1-D2)
  </code></pre>
  <p>for Avg - past 3 week difference</p>
  <pre><code>        LWK_Avg = 
  var Lwk=CALCULATE(MAX('Table'[WK]),ALL('Table'))
  var Ex_LWk=CALCULATE(MAX('Table'[WK])-1,ALL('Table')) // finding before last week 
  var BLwk=CALCULATE(MAX('Table'[WK])-3,ALL('Table')) // finding 3 weeks before ( excluding last week)
  var Avg1=CALCULATE([Total]/3,'Table'[WK]&gt;=BLwk&amp;&amp; 'Table'[WK]&lt;=Ex_LWk)
  var D1=CALCULATE([Total],'Table'[WK]=Lwk)
  
  return
  IF(ISINSCOPE('Table'[WK]),BLANK(),D1-Avg1)
    
  </code></pre>
  <p>Using matrix I have achieved the below</p>
  <p><a href="https://i.stack.imgur.com/BVWOR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BVWOR.png" alt="enter image description here" /></a></p>
  <p>if i add the LWK_avg i am getting the below result</p>
  <p><a href="https://i.stack.imgur.com/ZVuyb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZVuyb.png" alt="enter image description here" /></a></p>
  <p>I would like to get the result without measure are repeated just adding LWK_avg at the last</p>
  <p><a href="https://i.stack.imgur.com/ClmIF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ClmIF.png" alt="enter image description here" /></a></p>