<?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: Extended period chosen? in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Extended-period-chosen/m-p/4301922#M170819</link>
    <description>&lt;P&gt;To solve this in Power BI, you want to dynamically filter your data based on the &lt;STRONG&gt;Visit Date&lt;/STRONG&gt; range, showing &lt;STRONG&gt;Calendar Dates&lt;/STRONG&gt; and &lt;STRONG&gt;Sales&lt;/STRONG&gt; that fall within 5 days before the earliest "Visit Date" (MIN Visit Date) and 5 days after the latest "Visit Date" (MAX Visit Date).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's how you can achieve it:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Solution Using DAX&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;1. Calculated Table Approach&lt;/STRONG&gt;&lt;BR /&gt;Create a calculated table that dynamically includes the relevant rows.&lt;/P&gt;&lt;P&gt;DAX&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;FilteredSalesTable =
VAR MinVisitDate = MIN(Sales[visit date]) -- Earliest visit date in the filter context
VAR MaxVisitDate = MAX(Sales[visit date]) -- Latest visit date in the filter context

-- Calculate the desired range
VAR StartDate = MinVisitDate - 5
VAR EndDate = MaxVisitDate + 5

-- Filter the sales table for the relevant calendar dates
RETURN
FILTER(
Sales,
Sales[calendar date] &amp;gt;= StartDate &amp;amp;&amp;amp;
Sales[calendar date] &amp;lt;= EndDate
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;You can now use this table to display the filtered calendar dates and sales data in your visuals.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2. Measure Approach&lt;/STRONG&gt;&lt;BR /&gt;If you prefer to create a measure instead of a calculated table, you can use this DAX measure:&lt;/P&gt;&lt;P&gt;DAX&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;FilteredSales =
VAR MinVisitDate = MIN(Sales[visit date]) -- Earliest visit date
VAR MaxVisitDate = MAX(Sales[visit date]) -- Latest visit date

-- Calculate the range
VAR StartDate = MinVisitDate - 5
VAR EndDate = MaxVisitDate + 5

-- Sum sales within the range
RETURN
CALCULATE(
SUM(Sales[sale]),
Sales[calendar date] &amp;gt;= StartDate &amp;amp;&amp;amp;
Sales[calendar date] &amp;lt;= EndDate
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;This measure can be used in a visual where calendar date is on the axis, showing only the relevant sales totals.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;3. Additional Dynamic Filter Column (Optional)&lt;/STRONG&gt;&lt;BR /&gt;You can add a calculated column to identify whether each row falls within the desired range:&lt;/P&gt;&lt;P&gt;DAX&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;InRange =
VAR MinVisitDate = CALCULATE(MIN(Sales[visit date]), ALL(Sales))
VAR MaxVisitDate = CALCULATE(MAX(Sales[visit date]), ALL(Sales))

-- Calculate the range
VAR StartDate = MinVisitDate - 5
VAR EndDate = MaxVisitDate + 5

-- Check if calendar date is in range
RETURN
IF(
Sales[calendar date] &amp;gt;= StartDate &amp;amp;&amp;amp;
Sales[calendar date] &amp;lt;= EndDate,
1,
0
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;You can then filter your visuals to only include rows where InRange = 1.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;H3&gt;Steps to Implement:&lt;/H3&gt;&lt;OL&gt;&lt;LI&gt;&lt;STRONG&gt;Add Visit Date Filters&lt;/STRONG&gt;: Use slicers or filters for Visit Date to define the range.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Use the Calculated Table or Measure&lt;/STRONG&gt;: Depending on your choice, add the calculated table or the measure to your visuals.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Test Your Filters&lt;/STRONG&gt;: Ensure the 5-day adjustment before and after the visit date range works as intended.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Please Mark this as solution if it helps. Appreciate Kudos.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 26 Nov 2024 10:16:06 GMT</pubDate>
    <dc:creator>FarhanJeelani</dc:creator>
    <dc:date>2024-11-26T10:16:06Z</dc:date>
    <item>
      <title>Extended period chosen?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Extended-period-chosen/m-p/4301909#M170818</link>
      <description>&lt;P&gt;Hi people,&lt;/P&gt;&lt;P&gt;I hope you can help me with a challange:&lt;/P&gt;&lt;P&gt;I have a table, which partly looks like this:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;now, I want to use the "visit date" to choose a period ("from-to" date filter), but I need to see the "calendar dates" and "sale" by date,&amp;nbsp; 5 days before the "visit date"-period starts (MIN visit Date) and 5 days after the period ends (MAX visit date).&lt;BR /&gt;how do I make this DAX (it is possible to make a calculated table/column as well as a measure)?&lt;BR /&gt;All help and inspiration is appreciated. Thanks&lt;/P&gt;&lt;P&gt;Br,&lt;/P&gt;&lt;P&gt;JayJay0306&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2024 10:10:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Extended-period-chosen/m-p/4301909#M170818</guid>
      <dc:creator>jayjay0306</dc:creator>
      <dc:date>2024-11-26T10:10:04Z</dc:date>
    </item>
    <item>
      <title>Re: Extended period chosen?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Extended-period-chosen/m-p/4301922#M170819</link>
      <description>&lt;P&gt;To solve this in Power BI, you want to dynamically filter your data based on the &lt;STRONG&gt;Visit Date&lt;/STRONG&gt; range, showing &lt;STRONG&gt;Calendar Dates&lt;/STRONG&gt; and &lt;STRONG&gt;Sales&lt;/STRONG&gt; that fall within 5 days before the earliest "Visit Date" (MIN Visit Date) and 5 days after the latest "Visit Date" (MAX Visit Date).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's how you can achieve it:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Solution Using DAX&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;1. Calculated Table Approach&lt;/STRONG&gt;&lt;BR /&gt;Create a calculated table that dynamically includes the relevant rows.&lt;/P&gt;&lt;P&gt;DAX&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;FilteredSalesTable =
VAR MinVisitDate = MIN(Sales[visit date]) -- Earliest visit date in the filter context
VAR MaxVisitDate = MAX(Sales[visit date]) -- Latest visit date in the filter context

-- Calculate the desired range
VAR StartDate = MinVisitDate - 5
VAR EndDate = MaxVisitDate + 5

-- Filter the sales table for the relevant calendar dates
RETURN
FILTER(
Sales,
Sales[calendar date] &amp;gt;= StartDate &amp;amp;&amp;amp;
Sales[calendar date] &amp;lt;= EndDate
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;You can now use this table to display the filtered calendar dates and sales data in your visuals.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2. Measure Approach&lt;/STRONG&gt;&lt;BR /&gt;If you prefer to create a measure instead of a calculated table, you can use this DAX measure:&lt;/P&gt;&lt;P&gt;DAX&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;FilteredSales =
VAR MinVisitDate = MIN(Sales[visit date]) -- Earliest visit date
VAR MaxVisitDate = MAX(Sales[visit date]) -- Latest visit date

-- Calculate the range
VAR StartDate = MinVisitDate - 5
VAR EndDate = MaxVisitDate + 5

-- Sum sales within the range
RETURN
CALCULATE(
SUM(Sales[sale]),
Sales[calendar date] &amp;gt;= StartDate &amp;amp;&amp;amp;
Sales[calendar date] &amp;lt;= EndDate
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;This measure can be used in a visual where calendar date is on the axis, showing only the relevant sales totals.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;3. Additional Dynamic Filter Column (Optional)&lt;/STRONG&gt;&lt;BR /&gt;You can add a calculated column to identify whether each row falls within the desired range:&lt;/P&gt;&lt;P&gt;DAX&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;InRange =
VAR MinVisitDate = CALCULATE(MIN(Sales[visit date]), ALL(Sales))
VAR MaxVisitDate = CALCULATE(MAX(Sales[visit date]), ALL(Sales))

-- Calculate the range
VAR StartDate = MinVisitDate - 5
VAR EndDate = MaxVisitDate + 5

-- Check if calendar date is in range
RETURN
IF(
Sales[calendar date] &amp;gt;= StartDate &amp;amp;&amp;amp;
Sales[calendar date] &amp;lt;= EndDate,
1,
0
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;You can then filter your visuals to only include rows where InRange = 1.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;H3&gt;Steps to Implement:&lt;/H3&gt;&lt;OL&gt;&lt;LI&gt;&lt;STRONG&gt;Add Visit Date Filters&lt;/STRONG&gt;: Use slicers or filters for Visit Date to define the range.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Use the Calculated Table or Measure&lt;/STRONG&gt;: Depending on your choice, add the calculated table or the measure to your visuals.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Test Your Filters&lt;/STRONG&gt;: Ensure the 5-day adjustment before and after the visit date range works as intended.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Please Mark this as solution if it helps. Appreciate Kudos.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2024 10:16:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Extended-period-chosen/m-p/4301922#M170819</guid>
      <dc:creator>FarhanJeelani</dc:creator>
      <dc:date>2024-11-26T10:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: Extended period chosen?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Extended-period-chosen/m-p/4302141#M170822</link>
      <description>&lt;P&gt;thanks FarhanJeelani,&lt;/P&gt;&lt;P&gt;regarding your "measure"-solution:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks FarhanJeelani,&lt;/P&gt;&lt;P&gt;regarding your "measure"-solution:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think the return script needs more to work? You have only set it up with a "filter"-function? I have tried to wrap it up in a CALCULATION() finction, but it doesn't work:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;please advise. Thanks.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 26 Nov 2024 11:58:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Extended-period-chosen/m-p/4302141#M170822</guid>
      <dc:creator>jayjay0306</dc:creator>
      <dc:date>2024-11-26T11:58:48Z</dc:date>
    </item>
    <item>
      <title>Re: Extended period chosen?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Extended-period-chosen/m-p/4302351#M170826</link>
      <description>&lt;P&gt;hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="139186" data-lia-user-login="jayjay0306" class="lia-mention lia-mention-user"&gt;jayjay0306&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;try like:&lt;/P&gt;
&lt;P&gt;1.plot a slicer with a calculated table like:&lt;/P&gt;
&lt;P&gt;slicer=VALUES(data[visit date])&lt;/P&gt;
&lt;P&gt;2.plot a table visual with calendar dates column and sale column&lt;/P&gt;
&lt;P&gt;3.pull a measure like below to the fiter pane of the table visual and choose 1:&lt;/P&gt;
&lt;P&gt;measure =&lt;/P&gt;
&lt;P&gt;VAR _vdate=SELECTEDVALUE(slicer[visit date])&lt;/P&gt;
&lt;P&gt;VAR _date = MAX(data[calendar date])&lt;/P&gt;
&lt;P&gt;RETURN&lt;/P&gt;
&lt;P&gt;IF(&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; _date&amp;gt;=_vdate-5||_date&amp;lt;=_vdate+5,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; 1, 0&lt;/P&gt;
&lt;P&gt;)&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2024 14:21:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Extended-period-chosen/m-p/4302351#M170826</guid>
      <dc:creator>FreemanZ</dc:creator>
      <dc:date>2024-11-26T14:21:42Z</dc:date>
    </item>
    <item>
      <title>Re: Extended period chosen?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Extended-period-chosen/m-p/4303068#M170859</link>
      <description>&lt;P&gt;Hi all,thanks for the quick reply, I'll add more.&lt;/P&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="139186" data-lia-user-login="jayjay0306" class="lia-mention lia-mention-user"&gt;jayjay0306&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Please follow these steps:&lt;/P&gt;
&lt;P&gt;1.Use the following DAX expression to create a table&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Date Table = CALENDAR(MIN('Table'[visit date]),MAX('Table'[visit date]))&lt;/LI-CODE&gt;
&lt;P&gt;2.Use the following DAX expression to create a measure&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;_Sale = 
VAR _from = MIN('Date Table'[Date]) - 5
VAR _to = MAX('Date Table'[Date]) + 5
VAR _date = SELECTEDVALUE('Table'[calendar date])
RETURN
IF(_date &amp;gt;= _from &amp;amp;&amp;amp; _date &amp;lt;= _to , SUM('Table'[sale]))&lt;/LI-CODE&gt;
&lt;P&gt;3.Final output&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Wenbin Zhou&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2024 02:17:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Extended-period-chosen/m-p/4303068#M170859</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-27T02:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: Extended period chosen?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Extended-period-chosen/m-p/4303423#M170873</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="139186" data-lia-user-login="jayjay0306" class="lia-mention lia-mention-user"&gt;jayjay0306&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;New measure:&lt;/P&gt;&lt;PRE&gt;SalesInExtendedPeriod = &lt;BR /&gt;VAR MinVisitDate = CALCULATE(MIN('YourDataTable'[visit date]), ALLSELECTED('YourDataTable'))&lt;BR /&gt;VAR MaxVisitDate = CALCULATE(MAX('YourDataTable'[visit date]), ALLSELECTED('YourDataTable'))&lt;BR /&gt;&lt;BR /&gt;RETURN &lt;BR /&gt;SUMX(&lt;BR /&gt;FILTER(&lt;BR /&gt;'YourDataTable',&lt;BR /&gt;'YourDataTable'[calendar date] &amp;gt;= MinVisitDate - 5 &amp;amp;&amp;amp;&lt;BR /&gt;'YourDataTable'[calendar date] &amp;lt;= MaxVisitDate + 5&lt;BR /&gt;),&lt;BR /&gt;'YourDataTable'[sale]&lt;BR /&gt;)&lt;/PRE&gt;&lt;P&gt;You can use it in visuals directly to get the total sales over the extended dates.&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;span class="lia-unicode-emoji" title=":love_letter:"&gt;💌&lt;/span&gt; If this helped, a Kudos &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt; or Solution mark would be great! &lt;span class="lia-unicode-emoji" title=":party_popper:"&gt;🎉&lt;/span&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Kedar&lt;BR /&gt;&lt;A href="https://www.linkedin.com/in/kedar-pande" target="_blank" rel="noopener"&gt;Connect on LinkedIn&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2024 05:59:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Extended-period-chosen/m-p/4303423#M170873</guid>
      <dc:creator>Kedar_Pande</dc:creator>
      <dc:date>2024-11-27T05:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: Extended period chosen?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Extended-period-chosen/m-p/4304009#M170902</link>
      <description>&lt;P&gt;thanks&amp;nbsp;&lt;SPAN&gt;Wenbin Zhou, it works! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;have a nice day!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;br,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Jayjay0306&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2024 10:38:02 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Extended-period-chosen/m-p/4304009#M170902</guid>
      <dc:creator>jayjay0306</dc:creator>
      <dc:date>2024-11-27T10:38:02Z</dc:date>
    </item>
  </channel>
</rss>

