title: Should FILTER be used inside or outside of SUMMARIZE?
body: <p>I have these two queries:</p>
  
  <pre><code>EVALUATE
  FILTER (
      SUMMARIZE (
          'Sales',
          Products[ProductName],
          'Calendar'[CalendarYear],
          "Total Sales Amount", SUM ( Sales[SalesAmount] ),
          "Total Cost", SUM ( 'Sales'[TotalProductCost] )
      ),
      Products[ProductName] = "AWC Logo Cap"
  )
  ORDER BY
      Products[ProductName],
      'Calendar'[CalendarYear] ASC
  </code></pre>
  
  <p>and this:</p>
  
  <pre><code>EVALUATE
  SUMMARIZE (
      FILTER ( 'Sales', RELATED ( Products[ProductName] ) = "AWC Logo Cap" ),
      Products[ProductName],
      'Calendar'[CalendarYear],
      "Total Sales Amount", SUM ( Sales[SalesAmount] ),
      "Total Cost", SUM ( 'Sales'[TotalProductCost] )
  )
  ORDER BY
      Products[ProductName],
      'Calendar'[CalendarYear] ASC
  </code></pre>
  
  <p>Both return the following:</p>
  
  <p><a href="https://i.stack.imgur.com/3qrdO.png" rel="noreferrer"><img src="https://i.stack.imgur.com/3qrdO.png" alt="enter image description here"></a></p>
  
  <p>The only difference between the two queries is the positioning of the FILTER function - which is better practice and why?</p>
  
  <hr>
  
  <p>note</p>
  
  <p>So looking at the two sqlbi articles referenced by Alex we can do either of the following to potentially make things more performant but I'm still unsure if the FILTER function should happen inside or outside the other syntax:</p>
  
  <pre><code>EVALUATE
  FILTER (
      ADDCOLUMNS (
          SUMMARIZE ( 'Sales', Products[ProductName], 'Calendar'[CalendarYear] ),
          "Total Sales Amount", CALCULATE ( SUM ( Sales[SalesAmount] ) ),
          "Total Cost", CALCULATE ( SUM ( 'Sales'[TotalProductCost] ) )
      ),
      Products[ProductName] = "AWC Logo Cap"
  )
  ORDER BY
      Products[ProductName],
      'Calendar'[CalendarYear] ASC
  </code></pre>
  
  <p>And using the 'SUMMARIZECOLUMNS' function:</p>
  
  <pre><code>EVALUATE
  FILTER (
      SUMMARIZECOLUMNS (
          Products[ProductName],
          'Calendar'[CalendarYear],
          "Total Sales Amount", SUM ( Sales[SalesAmount] ),
          "Total Cost", SUM ( 'Sales'[TotalProductCost] )
      ),
      Products[ProductName] = "AWC Logo Cap"
  )
  ORDER BY
      Products[ProductName],
      'Calendar'[CalendarYear] ASC
  </code></pre>
  
  <hr>
  
  <p>note2  </p>
  
  <p>Looks like SUMMARIZECOLUMNS has a built in FILTER parameter so I'd guess that this is the best way to go to guard against performance issues:</p>
  
  <pre><code>EVALUATE
  SUMMARIZECOLUMNS (
      Products[ProductName],
      'Calendar'[CalendarYear],
      FILTER ( 'Products', Products[ProductName] = "AWC Logo Cap" ),
      "Total Sales Amount", SUM ( Sales[SalesAmount] ),
      "Total Cost", SUM ( 'Sales'[TotalProductCost] )
  )
  ORDER BY
      Products[ProductName],
      'Calendar'[CalendarYear] ASC
  </code></pre>