<?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: Filter with date slicer and dynamic offset in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filter-with-date-slicer-and-dynamic-offset/m-p/1137132#M16984</link>
    <description>Of course DATEADD does not work. If you take a good look at the documentation of this function, you'll see that it returns a table of dates (and this function should be used on a proper Date table, not on a column in a fact table - but the docs won't tell you this).&lt;BR /&gt;&lt;BR /&gt;Secondly, this line&lt;BR /&gt;&lt;BR /&gt;DATEADD(orders[order_date];var_offset;DAY) &amp;lt;= max_selected_date&lt;BR /&gt;&lt;BR /&gt;is not syntactically correct because you cannot compare a table to a scalar. Hence, it does not filter anything.&lt;BR /&gt;&lt;BR /&gt;Thirdly, you should create good models, not just ANY models. If your current model has just one big fact table without any dimensions (and I can see you don't have any Date dimension)... then I'd suggest you change this immediately if you don't want to have issues down the line.&lt;BR /&gt;&lt;BR /&gt;Here's something to learn about time-intelligence in DAX:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://www.sqlbi.com/tv/time-intelligence-in-microsoft-power-bi/" target="_blank"&gt;https://www.sqlbi.com/tv/time-intelligence-in-microsoft-power-bi/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;and here's a start to how to build correct models:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://www.youtube.com/watch?v=78d6mwR8GtA" target="_blank"&gt;https://www.youtube.com/watch?v=78d6mwR8GtA&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://www.youtube.com/watch?v=_quTwyvDfG0" target="_blank"&gt;https://www.youtube.com/watch?v=_quTwyvDfG0&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Best&lt;BR /&gt;D</description>
    <pubDate>Tue, 02 Jun 2020 21:26:49 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-06-02T21:26:49Z</dc:date>
    <item>
      <title>Filter with date slicer and dynamic offset</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filter-with-date-slicer-and-dynamic-offset/m-p/1135612#M16921</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to solve a situation with date slicers and a custom offset. I will try to explain it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table with orders and returns like this:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;id&lt;/TD&gt;&lt;TD&gt;order_date&lt;/TD&gt;&lt;TD&gt;return_date&lt;/TD&gt;&lt;TD&gt;units_bought&lt;/TD&gt;&lt;TD&gt;units_returned&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2020-04-20&lt;/TD&gt;&lt;TD&gt;null&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2020-04-25&lt;/TD&gt;&lt;TD&gt;null&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2020-04-27&lt;/TD&gt;&lt;TD&gt;2020-05-06&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2020-04-28&lt;/TD&gt;&lt;TD&gt;2020-05-06&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;(If the order has not been returned, it will have a null value in return_date column)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then, I have a date slicer linked with order_date column. So, when I select a time period from 1 of April to 30 of April, I will get all the lines of the table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I want to add a value called "offset" that will be related to the time the client has to return the order. For example, an offset of 10 days, will say that if the order has been bought on 1 of april, it can be returned up to 10 of april.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then, what I want is to use that offset to filter values of the table:&lt;/P&gt;&lt;P&gt;1) If the order hasn't any return, we should check that the order_date + offset is less than selected period. This is because we want to exclude the orders that are still live, the ones that the client can still return it&lt;/P&gt;&lt;P&gt;2) If the order has been returned, we should check that order_date + offset is less than return_date&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to start with the first condition, ignoring for the moment, the second one. However, my approach didn't work.&lt;/P&gt;&lt;P&gt;Here is the measure that I did:&lt;/P&gt;&lt;/DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;var max_selected_date = MAX(dates[id]) --the max day of date slicer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;BR /&gt;var var_offset = SELECTEDVALUE(OFFSET[OFFSET]) --the selected offset value&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;metric = CALCULATE(&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; SUM(orders[units_bought]);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; FILTER(&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;     orders;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;     DATEADD(orders[order_date];var_offset;DAY) &amp;lt;= max_selected_date&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;     )&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;)--the valid orders&lt;BR /&gt;&lt;BR /&gt;return metric&lt;BR /&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;Imagine that I select a date period from 1 to 30 of April, and an offset of 4 days. What I want is only the orders of the days 20 and 25 of april. The orders of 27 and 28 should not be considered because 27 + 4days = 1 of May, and 1 of May is greather than 30 of April. The order of 25 of may should be considered because 25 + 4 days = 29 of April, and 29 of April is included in the selected date period.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am doing wrong with my formula?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards!&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 02 Jun 2020 09:43:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filter-with-date-slicer-and-dynamic-offset/m-p/1135612#M16921</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-06-02T09:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: Filter with date slicer and dynamic offset</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filter-with-date-slicer-and-dynamic-offset/m-p/1136661#M16960</link>
      <description>&lt;P&gt;What exactly is going wrong? Which output are you getting / not getting compared to expected?&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 17:17:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filter-with-date-slicer-and-dynamic-offset/m-p/1136661#M16960</guid>
      <dc:creator>stevedep</dc:creator>
      <dc:date>2020-06-02T17:17:38Z</dc:date>
    </item>
    <item>
      <title>Re: Filter with date slicer and dynamic offset</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filter-with-date-slicer-and-dynamic-offset/m-p/1137047#M16979</link>
      <description>&lt;P&gt;The problem is that the orders are not filtered. It seems that the dateadd function is not working&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 20:28:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filter-with-date-slicer-and-dynamic-offset/m-p/1137047#M16979</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-06-02T20:28:26Z</dc:date>
    </item>
    <item>
      <title>Re: Filter with date slicer and dynamic offset</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filter-with-date-slicer-and-dynamic-offset/m-p/1137132#M16984</link>
      <description>Of course DATEADD does not work. If you take a good look at the documentation of this function, you'll see that it returns a table of dates (and this function should be used on a proper Date table, not on a column in a fact table - but the docs won't tell you this).&lt;BR /&gt;&lt;BR /&gt;Secondly, this line&lt;BR /&gt;&lt;BR /&gt;DATEADD(orders[order_date];var_offset;DAY) &amp;lt;= max_selected_date&lt;BR /&gt;&lt;BR /&gt;is not syntactically correct because you cannot compare a table to a scalar. Hence, it does not filter anything.&lt;BR /&gt;&lt;BR /&gt;Thirdly, you should create good models, not just ANY models. If your current model has just one big fact table without any dimensions (and I can see you don't have any Date dimension)... then I'd suggest you change this immediately if you don't want to have issues down the line.&lt;BR /&gt;&lt;BR /&gt;Here's something to learn about time-intelligence in DAX:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://www.sqlbi.com/tv/time-intelligence-in-microsoft-power-bi/" target="_blank"&gt;https://www.sqlbi.com/tv/time-intelligence-in-microsoft-power-bi/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;and here's a start to how to build correct models:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://www.youtube.com/watch?v=78d6mwR8GtA" target="_blank"&gt;https://www.youtube.com/watch?v=78d6mwR8GtA&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://www.youtube.com/watch?v=_quTwyvDfG0" target="_blank"&gt;https://www.youtube.com/watch?v=_quTwyvDfG0&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Best&lt;BR /&gt;D</description>
      <pubDate>Tue, 02 Jun 2020 21:26:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filter-with-date-slicer-and-dynamic-offset/m-p/1137132#M16984</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-06-02T21:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: Filter with date slicer and dynamic offset</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filter-with-date-slicer-and-dynamic-offset/m-p/1138053#M16998</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;sales_sum_slicer = 
VAR MaxDate = MAX ('Date'[Date] ) 
VAR MinDate = MIN('Date'[Date])
VAR DaysBeforeDatea= MaxDate - 4
RETURN

    CALCULATE (
       CALCULATE(SUM('Table'[units_bought]));          --
      'Date'[Date]&amp;lt;= DaysBeforeDatea; 'Date'[Date] &amp;gt;= MinDate;  
        ALL ( 'Date' )               
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;File is &lt;A href="https://1drv.ms/u/s!AvU6hhKLfmEcgdd58kckA41cVADkyA?e=gyu54u" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards, Steve&amp;nbsp;&lt;/P&gt;&lt;P&gt;pls mark as solved when your query has been answered.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2020 07:14:29 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filter-with-date-slicer-and-dynamic-offset/m-p/1138053#M16998</guid>
      <dc:creator>stevedep</dc:creator>
      <dc:date>2020-06-03T07:14:29Z</dc:date>
    </item>
  </channel>
</rss>

