<?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 Re: Creating Reusable Date Filters in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Creating-Reusable-Date-Filters/m-p/3371250#M126870</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="330311" data-lia-user-login="NicholasJackson" class="lia-mention lia-mention-user"&gt;NicholasJackson&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would recommend using Calculation Groups here.&lt;/P&gt;
&lt;P&gt;Calculation Groups can be used to apply common modifications to multiple measures, with time intelligence being a common example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The nice thing about Calculation Groups is that they can be applied either by a filter in the report, or by applying a filter in a DAX expression.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your case, you could create a Calculation Group with a Calculation Item for each date filter. You can then apply a particular date filter to a calculation by filtering on the Calcualation Item by name, avoiding having to rewrite the DAX each time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example of a calculation group (using DAX Script from Tabular Editor) with 5 Calculation Items:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;-----------------------------------------------------
-- Calculation Group: 'Date Filter Calculation Group'
-----------------------------------------------------
CALCULATIONGROUP 'Date Filter Calculation Group'[Date Filter]

    CALCULATIONITEM "Default" = SELECTEDMEASURE ()
        Ordinal = 0

    CALCULATIONITEM "YTD" = 
        CALCULATE (
            SELECTEDMEASURE (),
            DATESYTD ( 'Date'[Date] )
        )
        Ordinal = 1

    CALCULATIONITEM "Full Year" = 
        CALCULATE (
            SELECTEDMEASURE (),
            PARALLELPERIOD ( 'Date'[Date], 0, YEAR )
        )
        Ordinal = 2

    CALCULATIONITEM "Previous Full Year" = 
        CALCULATE (
            SELECTEDMEASURE (),
            PREVIOUSYEAR ( 'Date'[Date] )
        )
        Ordinal = 3

    CALCULATIONITEM "YTD as at TODAY" = 
        CALCULATE (
            SELECTEDMEASURE (),
            CALCULATETABLE (
                DATESYTD ( 'Date'[Date] ),
                'Date'[Date] = TODAY ()
            )
        )
        Ordinal = 4&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having created this Calculation Group, you can then apply a Calculation Item within a measure such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Sales Quantity YTD = 
CALCULATE (
    [Sales Quantity],
    'Date Filter Calculation Group'[Date Filter] = "YTD"
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also filter on a particular Calculation Item in the report to apply it to multiple measures at a report/page/visual level.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For general background on Calculation Groups, there are various articles such as:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.sqlbi.com/calculation-groups/" target="_blank" rel="noopener"&gt;https://www.sqlbi.com/calculation-groups/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;</description>
    <pubDate>Wed, 09 Aug 2023 01:05:54 GMT</pubDate>
    <dc:creator>OwenAuger</dc:creator>
    <dc:date>2023-08-09T01:05:54Z</dc:date>
    <item>
      <title>Creating Reusable Date Filters</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Creating-Reusable-Date-Filters/m-p/3370403#M126821</link>
      <description>&lt;P&gt;I have a simple measure that gets the total sales for the given year:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Total Sales (YTD) = CALCULATE(SUM([Sales Amount]), DATESYTD('Calendar'[Date]))&lt;/LI-CODE&gt;&lt;P&gt;I have another measure where I would like to use the same date calculation, but instead use a different calculation:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Total Orders (YTD) = CALCULATE(COUNTROWS('Sales'), DATESYTD('Calendar'[Date]))&lt;/LI-CODE&gt;&lt;P&gt;In this case, the filter calculation is quite simple as DATESYTD takes care of the heavy lifting. Copy/pasting the DATESYTD calcuation between measures isn't difficult or cumbersome. However, I have other date filters that are much more complex and need to be used in multiple measures.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I create a reusable (date) filter to use on multiple measures?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Few ideas:&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I could create a calculated table, but this seems like far too much overhead if I have 10+ date filters.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;This solution suggests creating a measure that simply has the filter criteria, but I'm afraid it may produce undesired results if used in the wrong context:&amp;nbsp;&lt;A href="https://community.fabric.microsoft.com/t5/Desktop/Creating-a-reusable-table-filter/m-p/1916927#M732781" target="_blank"&gt;https://community.fabric.microsoft.com/t5/Desktop/Creating-a-reusable-table-filter/m-p/1916927#M732781&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Tue, 08 Aug 2023 13:54:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Creating-Reusable-Date-Filters/m-p/3370403#M126821</guid>
      <dc:creator>NicholasJackson</dc:creator>
      <dc:date>2023-08-08T13:54:15Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Reusable Date Filters</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Creating-Reusable-Date-Filters/m-p/3371250#M126870</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="330311" data-lia-user-login="NicholasJackson" class="lia-mention lia-mention-user"&gt;NicholasJackson&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would recommend using Calculation Groups here.&lt;/P&gt;
&lt;P&gt;Calculation Groups can be used to apply common modifications to multiple measures, with time intelligence being a common example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The nice thing about Calculation Groups is that they can be applied either by a filter in the report, or by applying a filter in a DAX expression.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your case, you could create a Calculation Group with a Calculation Item for each date filter. You can then apply a particular date filter to a calculation by filtering on the Calcualation Item by name, avoiding having to rewrite the DAX each time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example of a calculation group (using DAX Script from Tabular Editor) with 5 Calculation Items:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;-----------------------------------------------------
-- Calculation Group: 'Date Filter Calculation Group'
-----------------------------------------------------
CALCULATIONGROUP 'Date Filter Calculation Group'[Date Filter]

    CALCULATIONITEM "Default" = SELECTEDMEASURE ()
        Ordinal = 0

    CALCULATIONITEM "YTD" = 
        CALCULATE (
            SELECTEDMEASURE (),
            DATESYTD ( 'Date'[Date] )
        )
        Ordinal = 1

    CALCULATIONITEM "Full Year" = 
        CALCULATE (
            SELECTEDMEASURE (),
            PARALLELPERIOD ( 'Date'[Date], 0, YEAR )
        )
        Ordinal = 2

    CALCULATIONITEM "Previous Full Year" = 
        CALCULATE (
            SELECTEDMEASURE (),
            PREVIOUSYEAR ( 'Date'[Date] )
        )
        Ordinal = 3

    CALCULATIONITEM "YTD as at TODAY" = 
        CALCULATE (
            SELECTEDMEASURE (),
            CALCULATETABLE (
                DATESYTD ( 'Date'[Date] ),
                'Date'[Date] = TODAY ()
            )
        )
        Ordinal = 4&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having created this Calculation Group, you can then apply a Calculation Item within a measure such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Sales Quantity YTD = 
CALCULATE (
    [Sales Quantity],
    'Date Filter Calculation Group'[Date Filter] = "YTD"
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also filter on a particular Calculation Item in the report to apply it to multiple measures at a report/page/visual level.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For general background on Calculation Groups, there are various articles such as:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.sqlbi.com/calculation-groups/" target="_blank" rel="noopener"&gt;https://www.sqlbi.com/calculation-groups/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2023 01:05:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Creating-Reusable-Date-Filters/m-p/3371250#M126870</guid>
      <dc:creator>OwenAuger</dc:creator>
      <dc:date>2023-08-09T01:05:54Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Reusable Date Filters</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Creating-Reusable-Date-Filters/m-p/3381084#M127378</link>
      <description>&lt;P&gt;This is exactly what I was looking for, thank you so much!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2023 17:34:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Creating-Reusable-Date-Filters/m-p/3381084#M127378</guid>
      <dc:creator>NicholasJackson</dc:creator>
      <dc:date>2023-08-15T17:34:32Z</dc:date>
    </item>
  </channel>
</rss>

