title: Calculating Variance and Variance% in Dax
body: <p>In my PBIX File, I have measures that calculate Revenue, COGS, Gross Margin etc.</p>
  
  <pre><code>Revenue = Sum(Amt)
  </code></pre>
  
  <p>More measures that calculate value for Last year Revenue_LY, COGS_LY and GM_LY.</p>
  
  <pre><code>Revenue_LY = CALCULATE (
    [Revenue],
    FILTER (
         ALL ( 'Date' ),
              'Date'[FinYear]= MAX ( 'Date'[FinYear] ) - 1 &amp;&amp; 'Date'[FinPeriod] = max('Date'[FinPeriod])
      )
   )
  </code></pre>
  
  <p>Now I need variance and variance% measures for each which compare data against last year and budget. The amount of measures is just getting too many. </p>
  
  <pre><code>Revenue_CY-LY = CALCULATE([Revenue],KEEPFILTERS(Versions[VersionCode] = "Act")) - CALCULATE([Revenue_LY],KEEPFILTERS(Versions[VersionCode] = "Act"))
  
  Revenue_CY-LY% = IF([Revenue_CY-LY] &lt; 0, -1, 1) *
                  IF(
                      ABS(DIVIDE([Revenue_CY-LY],[Revenue])) &gt; 99.9, 
                          "n/a",
                      ABS(DIVIDE([Revenue_CY-LY],[Revenue])*100)
              )
  </code></pre>
  
  <p>Is there a way to summarize the measures used. I don't want to create individual measures of each variance. </p>