<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Applying multiple filters on table (with the goal of avoiding repeated filters) in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Applying-multiple-filters-on-table-with-the-goal-of-avoiding/m-p/2823977#M89714</link>
    <description>&lt;P&gt;I have a report with slow visuals (to the point that it runs out of memory) and I am trying to optimize some of the DAX measures.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;It is a big report, but the model for the part that I am having problems has 4 tables shown below:&lt;BR /&gt;&lt;BR /&gt;&lt;img /&gt;&lt;BR /&gt;&lt;BR /&gt;and the current measure is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Capacity  = (CALCULATE(SUM(FactCapacityForecast[Value]),
                            FILTER('Shared DW_DimVersion', EDATE(MIN(DimDate[Date]),-1)='Shared DW_DimVersion'[FCStartDate]),
                           	FILTER('Shared DW_DimAccount','Shared DW_DimAccount'[AccountNumber]="CALC0008"),
                            DATESBETWEEN(DimDate[Date],MIN(DimDate[Date]),EDATE(min(DimDate[Date]),5)))
                        +
                      CALCULATE(SUM(FactCapacityForecast[Value]),
                            FILTER('Shared DW_DimVersion', EDATE(MIN(DimDate[Date]),-1)='Shared DW_DimVersion'[FCStartDate]),
                           	FILTER('Shared DW_DimAccount','Shared DW_DimAccount'[AccountNumber]="CALC0006"),
                            DATESBETWEEN(DimDate[Date],MIN(DimDate[Date]),EDATE(min(DimDate[Date]),5))))
                      *
                      (DIVIDE(
                        CALCULATE(SUM(FactCapacityForecast[Value]),
                            FILTER('Shared DW_DimVersion', EDATE(MIN(DimDate[Date]),-1)='Shared DW_DimVersion'[FCStartDate]),
                            FILTER('Shared DW_DimAccount','Shared DW_DimAccount'[AccountNumber]="CALC0017"),
                            DATESBETWEEN(DimDate[Date],MIN(DimDate[Date]),EDATE(min(DimDate[Date]),5))),
                        CALCULATE(SUM(FactCapacityForecast[Value]),
                            FILTER('Shared DW_DimVersion', EDATE(MIN(DimDate[Date]),-1)='Shared DW_DimVersion'[FCStartDate]),
                            FILTER('Shared DW_DimAccount','Shared DW_DimAccount'[AccountNumber]="CALC0016"),
                            DATESBETWEEN(DimDate[Date],MIN(DimDate[Date]),EDATE(min(DimDate[Date]),5)))))
                      *
                        (DIVIDE(
                        CALCULATE(SUM(FactCapacityForecast[Value]),
                            FILTER('Shared DW_DimVersion', EDATE(MIN(DimDate[Date]),-1)='Shared DW_DimVersion'[FCStartDate]),
                            FILTER('Shared DW_DimAccount','Shared DW_DimAccount'[AccountNumber]="CALC0005"),
                            DATESBETWEEN(DimDate[Date],MIN(DimDate[Date]),EDATE(min(DimDate[Date]),5))),
                        CALCULATE(SUM(FactCapacityForecast[Value]),
                            FILTER('Shared DW_DimVersion', EDATE(MIN(DimDate[Date]),-1)='Shared DW_DimVersion'[FCStartDate]),
                            FILTER('Shared DW_DimAccount','Shared DW_DimAccount'[AccountNumber]="CALC0006"),
                            DATESBETWEEN(DimDate[Date],MIN(DimDate[Date]),EDATE(min(DimDate[Date]),5))))*-1)*-1&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I believe this can be written in a more efficient and readable way. Right now the filters are applied on 3 tables ('Shared DW_DimVersion',&amp;nbsp;&lt;SPAN&gt;'Shared DW_DimAccount' and '&lt;/SPAN&gt;&lt;SPAN&gt;DimDate')&lt;/SPAN&gt;&amp;nbsp;in each of CALCULATE functions and 2 of those are just being repeated. I want to create a table variable where I first apply filters on&amp;nbsp;&lt;SPAN&gt;'Shared DW_DimVersion' and 'DimDate' only once and then use that variable to apply filter on&amp;nbsp;&lt;SPAN&gt;'Shared DW_DimAccount' afterwards.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Maybe the final measure can be something like this:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Capacity Optimized = 
                       VAR intermediate_table =
                        CALCULATETABLE(FactCapacityForecast,
                            //KEEPFILTERS(
                                FILTER(
                                //ALL ('Shared DW_DimVersion'[FCStartDate]),
                                'Shared DW_DimVersion',
                                EDATE(MIN('DimDate'[Date]),-1)='Shared DW_DimVersion'[FCStartDate]
                                )
                            //    )
                                ,
                            KEEPFILTERS(    DATESBETWEEN(DimDate[Date],MIN(DimDate[Date]),EDATE(min(DimDate[Date]),5))
                            )
                            //DATESINPERIOD('DimDate'[Date],MIN('DimDate'[Date]), 5, MONTH)
                            )

                        RETURN
                        (CALCULATE(SUMX(intermediate_table, FactCapacityForecast[Value]), 
                            KEEPFILTERS(
                            FILTER(
                                //ALL ('Shared DW_DimAccount'[AccountNumber]),
                                'Shared DW_DimAccount',
                                'Shared DW_DimAccount'[AccountNumber] = "CALC0008"
                                )
                            )
                        ) 
                        +
                        CALCULATE(SUMX(intermediate_table, FactCapacityForecast[Value]), 
                            KEEPFILTERS(
                            FILTER(
                                //ALL ('Shared DW_DimAccount'[AccountNumber]),
                                'Shared DW_DimAccount',
                                'Shared DW_DimAccount'[AccountNumber] = "CALC0006"
                                )
                            )
                        ))
                        *
                        DIVIDE(
                            CALCULATE(SUMX(intermediate_table, FactCapacityForecast[Value]), 
                            KEEPFILTERS(
                            FILTER(
                                //ALL ('Shared DW_DimAccount'[AccountNumber]),
                                'Shared DW_DimAccount',
                                'Shared DW_DimAccount'[AccountNumber]  = "CALC0017"
                                )
                            )
                        ),
                            CALCULATE(SUMX(intermediate_table, FactCapacityForecast[Value]), 
                            KEEPFILTERS(
                                FILTER(
                                //ALL ('Shared DW_DimAccount'[AccountNumber]),
                                'Shared DW_DimAccount',
                                'Shared DW_DimAccount'[AccountNumber] = "CALC0016"
                                )
                            )
                            )
                        )
                        *
                        (DIVIDE(
                            CALCULATE(SUMX(intermediate_table, FactCapacityForecast[Value]), 
                            KEEPFILTERS(
                            FILTER(
                                ALL ('Shared DW_DimAccount'[AccountNumber]),
                                'Shared DW_DimAccount'[AccountNumber] = "CALC0005"
                                )
                            )
                        ),
                            CALCULATE(SUMX(intermediate_table, FactCapacityForecast[Value]), 
                            KEEPFILTERS(
                            FILTER(
                                ALL ('Shared DW_DimAccount'[AccountNumber]),
                                'Shared DW_DimAccount'[AccountNumber] = "CALC0006"
                                )
                            )
                            )
                        )*-1)*-1&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;The results are supposed to be used in a matrix alongside 'DimDate[Month]' values.&amp;nbsp;&lt;BR /&gt;I have been playing around with different functions, but cannot get the same number as the original measure.&amp;nbsp;&lt;BR /&gt;How can I get the correct measure?&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;BR /&gt;Moe&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="6799" data-lia-user-login="OwenAuger" class="lia-mention lia-mention-user"&gt;OwenAuger&lt;/a&gt;&amp;nbsp;I think you have a good solution for this problem as well &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 06 Oct 2022 21:15:40 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2022-10-06T21:15:40Z</dc:date>
    <item>
      <title>Applying multiple filters on table (with the goal of avoiding repeated filters)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Applying-multiple-filters-on-table-with-the-goal-of-avoiding/m-p/2823977#M89714</link>
      <description>&lt;P&gt;I have a report with slow visuals (to the point that it runs out of memory) and I am trying to optimize some of the DAX measures.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;It is a big report, but the model for the part that I am having problems has 4 tables shown below:&lt;BR /&gt;&lt;BR /&gt;&lt;img /&gt;&lt;BR /&gt;&lt;BR /&gt;and the current measure is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Capacity  = (CALCULATE(SUM(FactCapacityForecast[Value]),
                            FILTER('Shared DW_DimVersion', EDATE(MIN(DimDate[Date]),-1)='Shared DW_DimVersion'[FCStartDate]),
                           	FILTER('Shared DW_DimAccount','Shared DW_DimAccount'[AccountNumber]="CALC0008"),
                            DATESBETWEEN(DimDate[Date],MIN(DimDate[Date]),EDATE(min(DimDate[Date]),5)))
                        +
                      CALCULATE(SUM(FactCapacityForecast[Value]),
                            FILTER('Shared DW_DimVersion', EDATE(MIN(DimDate[Date]),-1)='Shared DW_DimVersion'[FCStartDate]),
                           	FILTER('Shared DW_DimAccount','Shared DW_DimAccount'[AccountNumber]="CALC0006"),
                            DATESBETWEEN(DimDate[Date],MIN(DimDate[Date]),EDATE(min(DimDate[Date]),5))))
                      *
                      (DIVIDE(
                        CALCULATE(SUM(FactCapacityForecast[Value]),
                            FILTER('Shared DW_DimVersion', EDATE(MIN(DimDate[Date]),-1)='Shared DW_DimVersion'[FCStartDate]),
                            FILTER('Shared DW_DimAccount','Shared DW_DimAccount'[AccountNumber]="CALC0017"),
                            DATESBETWEEN(DimDate[Date],MIN(DimDate[Date]),EDATE(min(DimDate[Date]),5))),
                        CALCULATE(SUM(FactCapacityForecast[Value]),
                            FILTER('Shared DW_DimVersion', EDATE(MIN(DimDate[Date]),-1)='Shared DW_DimVersion'[FCStartDate]),
                            FILTER('Shared DW_DimAccount','Shared DW_DimAccount'[AccountNumber]="CALC0016"),
                            DATESBETWEEN(DimDate[Date],MIN(DimDate[Date]),EDATE(min(DimDate[Date]),5)))))
                      *
                        (DIVIDE(
                        CALCULATE(SUM(FactCapacityForecast[Value]),
                            FILTER('Shared DW_DimVersion', EDATE(MIN(DimDate[Date]),-1)='Shared DW_DimVersion'[FCStartDate]),
                            FILTER('Shared DW_DimAccount','Shared DW_DimAccount'[AccountNumber]="CALC0005"),
                            DATESBETWEEN(DimDate[Date],MIN(DimDate[Date]),EDATE(min(DimDate[Date]),5))),
                        CALCULATE(SUM(FactCapacityForecast[Value]),
                            FILTER('Shared DW_DimVersion', EDATE(MIN(DimDate[Date]),-1)='Shared DW_DimVersion'[FCStartDate]),
                            FILTER('Shared DW_DimAccount','Shared DW_DimAccount'[AccountNumber]="CALC0006"),
                            DATESBETWEEN(DimDate[Date],MIN(DimDate[Date]),EDATE(min(DimDate[Date]),5))))*-1)*-1&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I believe this can be written in a more efficient and readable way. Right now the filters are applied on 3 tables ('Shared DW_DimVersion',&amp;nbsp;&lt;SPAN&gt;'Shared DW_DimAccount' and '&lt;/SPAN&gt;&lt;SPAN&gt;DimDate')&lt;/SPAN&gt;&amp;nbsp;in each of CALCULATE functions and 2 of those are just being repeated. I want to create a table variable where I first apply filters on&amp;nbsp;&lt;SPAN&gt;'Shared DW_DimVersion' and 'DimDate' only once and then use that variable to apply filter on&amp;nbsp;&lt;SPAN&gt;'Shared DW_DimAccount' afterwards.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Maybe the final measure can be something like this:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Capacity Optimized = 
                       VAR intermediate_table =
                        CALCULATETABLE(FactCapacityForecast,
                            //KEEPFILTERS(
                                FILTER(
                                //ALL ('Shared DW_DimVersion'[FCStartDate]),
                                'Shared DW_DimVersion',
                                EDATE(MIN('DimDate'[Date]),-1)='Shared DW_DimVersion'[FCStartDate]
                                )
                            //    )
                                ,
                            KEEPFILTERS(    DATESBETWEEN(DimDate[Date],MIN(DimDate[Date]),EDATE(min(DimDate[Date]),5))
                            )
                            //DATESINPERIOD('DimDate'[Date],MIN('DimDate'[Date]), 5, MONTH)
                            )

                        RETURN
                        (CALCULATE(SUMX(intermediate_table, FactCapacityForecast[Value]), 
                            KEEPFILTERS(
                            FILTER(
                                //ALL ('Shared DW_DimAccount'[AccountNumber]),
                                'Shared DW_DimAccount',
                                'Shared DW_DimAccount'[AccountNumber] = "CALC0008"
                                )
                            )
                        ) 
                        +
                        CALCULATE(SUMX(intermediate_table, FactCapacityForecast[Value]), 
                            KEEPFILTERS(
                            FILTER(
                                //ALL ('Shared DW_DimAccount'[AccountNumber]),
                                'Shared DW_DimAccount',
                                'Shared DW_DimAccount'[AccountNumber] = "CALC0006"
                                )
                            )
                        ))
                        *
                        DIVIDE(
                            CALCULATE(SUMX(intermediate_table, FactCapacityForecast[Value]), 
                            KEEPFILTERS(
                            FILTER(
                                //ALL ('Shared DW_DimAccount'[AccountNumber]),
                                'Shared DW_DimAccount',
                                'Shared DW_DimAccount'[AccountNumber]  = "CALC0017"
                                )
                            )
                        ),
                            CALCULATE(SUMX(intermediate_table, FactCapacityForecast[Value]), 
                            KEEPFILTERS(
                                FILTER(
                                //ALL ('Shared DW_DimAccount'[AccountNumber]),
                                'Shared DW_DimAccount',
                                'Shared DW_DimAccount'[AccountNumber] = "CALC0016"
                                )
                            )
                            )
                        )
                        *
                        (DIVIDE(
                            CALCULATE(SUMX(intermediate_table, FactCapacityForecast[Value]), 
                            KEEPFILTERS(
                            FILTER(
                                ALL ('Shared DW_DimAccount'[AccountNumber]),
                                'Shared DW_DimAccount'[AccountNumber] = "CALC0005"
                                )
                            )
                        ),
                            CALCULATE(SUMX(intermediate_table, FactCapacityForecast[Value]), 
                            KEEPFILTERS(
                            FILTER(
                                ALL ('Shared DW_DimAccount'[AccountNumber]),
                                'Shared DW_DimAccount'[AccountNumber] = "CALC0006"
                                )
                            )
                            )
                        )*-1)*-1&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;The results are supposed to be used in a matrix alongside 'DimDate[Month]' values.&amp;nbsp;&lt;BR /&gt;I have been playing around with different functions, but cannot get the same number as the original measure.&amp;nbsp;&lt;BR /&gt;How can I get the correct measure?&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;BR /&gt;Moe&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="6799" data-lia-user-login="OwenAuger" class="lia-mention lia-mention-user"&gt;OwenAuger&lt;/a&gt;&amp;nbsp;I think you have a good solution for this problem as well &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2022 21:15:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Applying-multiple-filters-on-table-with-the-goal-of-avoiding/m-p/2823977#M89714</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-10-06T21:15:40Z</dc:date>
    </item>
    <item>
      <title>Re: Applying multiple filters on table (with the goal of avoiding repeated filters)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Applying-multiple-filters-on-table-with-the-goal-of-avoiding/m-p/2824314#M89741</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please try&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;Capacity =
VAR MinDate =
    MIN ( DimDate[Date] )
VAR DimVersion =
    FILTER (
        'Shared DW_DimVersion',
        'Shared DW_DimVersion'[FCStartDate] = EDATE ( MinDate, -1 )
    )
VAR Dates =
    DATESBETWEEN ( DimDate[Date], MinDate, EDATE ( MinDate, 5 ) )
VAR FactCapacity =
    CALCULATETABLE ( FactCapacityForecast, DimVersion, Dates )
VAR CALC0005 =
    CALCULATE (
        SUM ( FactCapacityForecast[Value] ),
        FactCapacity,
        'Shared DW_DimAccount'[AccountNumber] = "CALC0005"
    )
VAR CALC0006 =
    CALCULATE (
        SUM ( FactCapacityForecast[Value] ),
        FactCapacity,
        'Shared DW_DimAccount'[AccountNumber] = "CALC0006"
    )
VAR CALC0008 =
    CALCULATE (
        SUM ( FactCapacityForecast[Value] ),
        FactCapacity,
        'Shared DW_DimAccount'[AccountNumber] = "CALC0008"
    )
VAR CALC0016 =
    CALCULATE (
        SUM ( FactCapacityForecast[Value] ),
        FactCapacity,
        'Shared DW_DimAccount'[AccountNumber] = "CALC0016"
    )
VAR CALC0017 =
    CALCULATE (
        SUM ( FactCapacityForecast[Value] ),
        FactCapacity,
        'Shared DW_DimAccount'[AccountNumber] = "CALC0017"
    )
RETURN
    ( CALC0008 + CALC0006 )
        * ( DIVIDE ( CALC0017, CALC0016 ) )
        * ( DIVIDE ( CALC0005, CALC0006 ) * -1 ) * -1&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 02:52:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Applying-multiple-filters-on-table-with-the-goal-of-avoiding/m-p/2824314#M89741</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-10-07T02:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: Applying multiple filters on table (with the goal of avoiding repeated filters)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Applying-multiple-filters-on-table-with-the-goal-of-avoiding/m-p/2830621#M90168</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="317289" data-lia-user-login="tamerj1" class="lia-mention lia-mention-user"&gt;tamerj1&lt;/a&gt;&amp;nbsp;Amazing! Thanks! Runs faster and much more readable.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Oct 2022 10:12:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Applying-multiple-filters-on-table-with-the-goal-of-avoiding/m-p/2830621#M90168</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-10-10T10:12:33Z</dc:date>
    </item>
  </channel>
</rss>

