<?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: DATESINPERIOD - filter context handling with Page Date slicer, do I need a CALCULATETABLE? in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DATESINPERIOD-filter-context-handling-with-Page-Date-slicer-do-I/m-p/4119561#M163556</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="452756" data-lia-user-login="rpiboy_1" class="lia-mention lia-mention-user"&gt;rpiboy_1&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Yes, &lt;STRONG&gt;DATESINPERIOD&lt;/STRONG&gt; respects the slicer context, so it won't include dates outside the slicer range, which might cause inaccuracies. Your version with &lt;STRONG&gt;CALCULATETABLE&lt;/STRONG&gt; and &lt;STRONG&gt;ALL('Date'[Date])&lt;/STRONG&gt; is better because it ensures all needed dates are considered for accurate rolling averages.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P align="center"&gt;&lt;FONT face="verdana,geneva"&gt;&lt;FONT color="#99CC00"&gt;&lt;STRONG&gt;Did I answer your question?&amp;nbsp;&lt;/STRONG&gt; &lt;FONT color="#99CC00"&gt;&lt;STRONG&gt;If so, please mark my post as the solution!&lt;span class="lia-unicode-emoji" title=":heavy_check_mark:"&gt;✔️&lt;/span&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva"&gt;&lt;FONT color="#99CC00"&gt;&lt;STRONG&gt;Your Kudos are much appreciated!&amp;nbsp;&lt;/STRONG&gt; &lt;FONT color="#99CC00"&gt;&lt;STRONG&gt;Proud to be a Responsive Resident!&lt;/STRONG&gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Aug 2024 01:00:13 GMT</pubDate>
    <dc:creator>ahadkarimi</dc:creator>
    <dc:date>2024-08-27T01:00:13Z</dc:date>
    <item>
      <title>DATESINPERIOD - filter context handling with Page Date slicer, do I need a CALCULATETABLE?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DATESINPERIOD-filter-context-handling-with-Page-Date-slicer-do-I/m-p/4119555#M163555</link>
      <description>&lt;UL&gt;&lt;LI&gt;I have a well formed Date Table (thanks Bravo).&lt;/LI&gt;&lt;LI&gt;I have a report page with a slicer on it that allows the user to define a date range (BETWEEN)&lt;/LI&gt;&lt;LI&gt;I'm calculating rolling average as per SQLBI&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Logins R6M = 
VAR _noMonths = 6
VAR _lastSelectedDate = MAX('Date'[Date])
VAR _period = 
    DATESINPERIOD( 'Date'[Date], _lastSelectedDate, -_noMonths, MONTH)
VAR _result =
    CALCULATE(
        AVERAGEX(
            VALUES('Date'[Fiscal Month Number]),
            [Logins (sum)]
        ),
        _period
    )
VAR _lastDateWithLogin = MAX( 'Monthly User Activity by Project'[Date])
VAR _firstVisibleDate = MIN('Date'[Date])
RETURN
    IF( _firstVisibleDate &amp;lt;= _lastDateWithLogin, _result)​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I know that DATESINPERIOD is 'sugar syntax' around DAX that I could write myself.&lt;UL&gt;&lt;LI&gt;what I don't recall, does DATESINPERIOD apply a CALCULATETABLE to the 'Date' table?&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;That is, if the period on the page (thanks to the slicer) started at Jan 1, 2022, will the calculation for 1/1/2022 account for the six months of 2021 that are not included in the slicer range?&lt;/LI&gt;&lt;LI&gt;I'm asking because I was thinking that the context from the slicer on page would be strictly applied, in which case the first period of averages would be in-accurate because it would be missing data.&lt;/LI&gt;&lt;LI&gt;I wrote a version of the above including a CALCULATETABLE, but both measures report the same data.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Logins R6M (filter) = 
VAR _noMonths = 6
VAR _lastSelectedDate = MAX('Date'[Date])

VAR _period = 
    CALCULATETABLE(
        DATESINPERIOD(
            'Date'[Date],
            _lastSelectedDate,
            -_noMonths,
            MONTH
        ),
        ALL('Date'[Date])
    )

VAR _result =
    CALCULATE(
        AVERAGEX(
            VALUES('Date'[Fiscal Month Number]),
            [Logins (sum)]
        ),
        _period
    )

VAR _lastDateWithLogin = MAX( 'Monthly User Activity by Project'[Date])
VAR _firstVisibleDate = MIN('Date'[Date])
RETURN
    IF( _firstVisibleDate &amp;lt;= _lastDateWithLogin, _result)​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2024 00:42:19 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DATESINPERIOD-filter-context-handling-with-Page-Date-slicer-do-I/m-p/4119555#M163555</guid>
      <dc:creator>rpiboy_1</dc:creator>
      <dc:date>2024-08-27T00:42:19Z</dc:date>
    </item>
    <item>
      <title>Re: DATESINPERIOD - filter context handling with Page Date slicer, do I need a CALCULATETABLE?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DATESINPERIOD-filter-context-handling-with-Page-Date-slicer-do-I/m-p/4119561#M163556</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="452756" data-lia-user-login="rpiboy_1" class="lia-mention lia-mention-user"&gt;rpiboy_1&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Yes, &lt;STRONG&gt;DATESINPERIOD&lt;/STRONG&gt; respects the slicer context, so it won't include dates outside the slicer range, which might cause inaccuracies. Your version with &lt;STRONG&gt;CALCULATETABLE&lt;/STRONG&gt; and &lt;STRONG&gt;ALL('Date'[Date])&lt;/STRONG&gt; is better because it ensures all needed dates are considered for accurate rolling averages.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P align="center"&gt;&lt;FONT face="verdana,geneva"&gt;&lt;FONT color="#99CC00"&gt;&lt;STRONG&gt;Did I answer your question?&amp;nbsp;&lt;/STRONG&gt; &lt;FONT color="#99CC00"&gt;&lt;STRONG&gt;If so, please mark my post as the solution!&lt;span class="lia-unicode-emoji" title=":heavy_check_mark:"&gt;✔️&lt;/span&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva"&gt;&lt;FONT color="#99CC00"&gt;&lt;STRONG&gt;Your Kudos are much appreciated!&amp;nbsp;&lt;/STRONG&gt; &lt;FONT color="#99CC00"&gt;&lt;STRONG&gt;Proud to be a Responsive Resident!&lt;/STRONG&gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2024 01:00:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DATESINPERIOD-filter-context-handling-with-Page-Date-slicer-do-I/m-p/4119561#M163556</guid>
      <dc:creator>ahadkarimi</dc:creator>
      <dc:date>2024-08-27T01:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: DATESINPERIOD - filter context handling with Page Date slicer, do I need a CALCULATETABLE?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DATESINPERIOD-filter-context-handling-with-Page-Date-slicer-do-I/m-p/4120560#M163595</link>
      <description>&lt;P&gt;&amp;nbsp;If my logic is correct, that is I do need to extend the period outside the scope of the Page Slicer, then why do both measures return the exact same values for the first dates shown. There should be at least some deviation between the two measures for the first 'period', eventually coming into alignment the further away you get from the 'start'.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2024 10:50:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DATESINPERIOD-filter-context-handling-with-Page-Date-slicer-do-I/m-p/4120560#M163595</guid>
      <dc:creator>rpiboy_1</dc:creator>
      <dc:date>2024-08-27T10:50:17Z</dc:date>
    </item>
  </channel>
</rss>

