title: Percent of Total Windowed in Power BI DAX
body: <p>I have these two tables:</p>
  
  <p>A data table...</p>
  
  <pre><code>ImaginaryData = 
  DATATABLE (
      "Fruit", STRING,
      "Colour", STRING, 
      "Amount", INTEGER, 
      { 
          { "Apple", "Red", 10 }, 
          { "Apple", "Green", 5 },
          { "Pear", "Pink", 100 },
          { "Pear", "Blue", 65 },
          { "Orange", "Black", 12 },
          { "Orange", "White", 8 }
      } )
  </code></pre>
  
  <p>A lookup table...</p>
  
  <pre><code>ImaginaryLookup = 
  DATATABLE (
      "Fruit", STRING, 
      { 
          { "Apple" }, 
          { "Pear" },
          { "Orange" }
      } )
  </code></pre>
  
  <p>Then I created this simple 1-to-many relationship:</p>
  
  <p><a href="https://i.stack.imgur.com/4XuKC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4XuKC.png" alt="enter image description here"></a></p>
  
  <p>Now I am trying to create a Percent of Total measure to add to a table - but I want the percent of total to be based on the total of the fruits that are selected in a slicer of ImaginaryLookup:</p>
  
  <p>This is what I have tried:</p>
  
  <pre><code> %Total = 
  DIVIDE(
      sum( ImaginaryData[Amount] ),
      CALCULATE(
          sum( ImaginaryData[Amount] ),
          ALL(ImaginaryData)
      )
  )
  </code></pre>
  
  <p>If all fruits are selected in the slicer then it works fine as I'd expect:</p>
  
  <p><a href="https://i.stack.imgur.com/4xbLE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4xbLE.png" alt="enter image description here"></a></p>
  
  <p>But if I select say "Orange" then the results are not what I want, as I'd like the 12 and the 8 to be a percentage of 20:</p>
  
  <p><a href="https://i.stack.imgur.com/vAhQ9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vAhQ9.png" alt="enter image description here"></a></p>
  
  <p>This also does not give me what I want:</p>
  
  <pre><code>%Total = 
  DIVIDE(
      sum( ImaginaryData[Amount] ),
      CALCULATE(
          sum( ImaginaryData[Amount] ),
          ALLEXCEPT(ImaginaryData, ImaginaryData[Fruit])
      )
  )
  </code></pre>
  
  <p>Because now if I select say Pears and Oranges then it is giving me the percent as a percent of each fruits total, rather than the percent of 185:</p>
  
  <p><a href="https://i.stack.imgur.com/96lLe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/96lLe.png" alt="enter image description here"></a></p>
  
  <hr>
  
  <p>note to Alexis</p>
  
  <p>If I try this:</p>
  
  <pre><code>%Total = 
  DIVIDE(
      sum( ImaginaryData[Amount] ),
      CALCULATE(
          sum( ImaginaryData[Amount] ),
          ALLSELECTED( ImaginaryData[Fruit])
      )
  )
  </code></pre>
  
  <p>I get this:</p>
  
  <p><a href="https://i.stack.imgur.com/E2Rqz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E2Rqz.png" alt="enter image description here"></a></p>