<?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: Using DATEDIFF in measure in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-DATEDIFF-in-measure/m-p/1543427#M30438</link>
    <description>&lt;P&gt;Here's the article I alluded to above:&amp;nbsp;&lt;A href="https://docs.microsoft.com/en-us/power-bi/guidance/star-schema" target="_blank"&gt;Understand star schema and the importance for Power BI - Power BI | Microsoft Docs&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 10 Dec 2020 15:40:16 GMT</pubDate>
    <dc:creator>daxer-almighty</dc:creator>
    <dc:date>2020-12-10T15:40:16Z</dc:date>
    <item>
      <title>Using DATEDIFF in measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-DATEDIFF-in-measure/m-p/1543228#M30419</link>
      <description>&lt;P&gt;Hello! I've spent some time attempting to use DATEDIFF in a dax measure but failed to do so. Here's the basics; I have two tables, "Sales" and "Stores". I am trying to display sales over time within a one year period and display the sales of store that have not been opened within that year. I also have a year slicer (which is properly working without the filter) like so:&lt;/P&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I try to add the desired filter, the graph display: "Cannot display values". Here is my dax measure:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Sales Filter = CALCULATE( SUM(Sales[sale]),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;FILTER(Sales,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DATEDIFF(RELATED(Stores[OpenedDate]), VALUES( Sale[Date] ), YEAR) &amp;gt; 1&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks for the help in advance!&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 10 Dec 2020 14:01:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-DATEDIFF-in-measure/m-p/1543228#M30419</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-12-10T14:01:09Z</dc:date>
    </item>
    <item>
      <title>Re: Using DATEDIFF in measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-DATEDIFF-in-measure/m-p/1543245#M30421</link>
      <description>&lt;P&gt;Hi Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's try and clarify. You say you want to &lt;EM&gt;display the sales of store that have not been opened within that year&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;What does that mean exactly and what fields would be used to determine it? Please provide examples to clarify: shops that will be included and shop that will be excluded&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Please mark the question solved when done and consider &lt;FONT color="#FF9900"&gt;giving a thumbs up if posts are helpful.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;Contact me privately for support with any larger-scale BI needs, tutoring, etc.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Cheers&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 14:10:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-DATEDIFF-in-measure/m-p/1543245#M30421</guid>
      <dc:creator>AlB</dc:creator>
      <dc:date>2020-12-10T14:10:32Z</dc:date>
    </item>
    <item>
      <title>Re: Using DATEDIFF in measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-DATEDIFF-in-measure/m-p/1543263#M30425</link>
      <description>&lt;P&gt;Hey! Yes that is precisely what I am attempting to do. To&amp;nbsp;&lt;EM&gt;display the sales of store that have not been opened within that year &lt;/EM&gt;as you say.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the "Stores" table, a column named "OpenedDate" displays the opening date of the store (dd-mm-year). Whether or not a store should be dispayed in the sales is determined if its opening date is the same as the selected year.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In other words, with the year slicer on year 2020, the store of ID 1 with an opening date of 01-01-2020 should be excluded while store of ID 2 with an opening date of 01-01-2015 should not.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 14:22:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-DATEDIFF-in-measure/m-p/1543263#M30425</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-12-10T14:22:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using DATEDIFF in measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-DATEDIFF-in-measure/m-p/1543386#M30433</link>
      <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Sales Filter =
VAR CurrentYear_ =
    YEAR ( MAX ( DateT[Date] ) ) // This could also be:  VAR CurrentYear_ = MAX(DateT[Year]) 
RETURN
    CALCULATE (
        SUM ( Sales[sale] ),
        FILTER ( Sales, YEAR ( RELATED ( Stores[OpenedDate] ) ) &amp;lt;&amp;gt; currentYear_ )
    )&lt;/LI-CODE&gt;
&lt;P&gt;&lt;STRONG&gt;Please mark the question solved when done and consider &lt;FONT color="#FF9900"&gt;giving a thumbs up if posts are helpful.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;Contact me privately for support with any larger-scale BI needs, tutoring, etc.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Cheers&amp;nbsp;&lt;/P&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;</description>
      <pubDate>Thu, 10 Dec 2020 15:15:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-DATEDIFF-in-measure/m-p/1543386#M30433</guid>
      <dc:creator>AlB</dc:creator>
      <dc:date>2020-12-10T15:15:18Z</dc:date>
    </item>
    <item>
      <title>Re: Using DATEDIFF in measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-DATEDIFF-in-measure/m-p/1543421#M30437</link>
      <description>&lt;LI-CODE lang="csharp"&gt;// For this to work you have to have a correct model.
// If you want to see what a correct model means you
// can ask Google this phrase "star schema in power bi"
// and a Microsoft page should appear near the top of the
// page, if not at the top. Please do READ IT.
// You need at least 3 tables with the following
// characteristics:
// 1. Sales table that will be your fact table (hidden).
// 2. Stores table that will hold all your stores.
//    this is your dimension.
// 3. Dates table that will be the calendar in the
//    model.
// Of course, a correct model will also very likely 
// have a dimension called Customers. The Date table
// will join to the fact table on the sales date.
// I think in your case the column with the sales date
// is called just Sales[Date]. With all this in place,
// you can then write:

[Sales Filtered] =
// The assumption is that the period in the
// current context does not span more than
// 1 year. Otherwise the measure returns BLANK.
var __currentYear = SELECTEDVALUE( Dates[Year] )
// This variable will store StoreID's of stores
// as visible in the current context but such
// that have their Stores[OpenedDate] before
// the __currentYear.
var __storesThatOpenedBeforeTheYear =
    CALCULATETABLE(
        DISTINCT( Stores[StoreID] ),
        KEEPFILTERS(
            YEAR( Stores[OpenedDate] ) &amp;lt; __currentYear
        )
    )
var __output =
    CALCULATE(
        SUM( Sales[Sale] ),
        __storesThatOpenedBeforeTheYear
    )
return
    __output&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 10 Dec 2020 15:35:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-DATEDIFF-in-measure/m-p/1543421#M30437</guid>
      <dc:creator>daxer-almighty</dc:creator>
      <dc:date>2020-12-10T15:35:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using DATEDIFF in measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-DATEDIFF-in-measure/m-p/1543427#M30438</link>
      <description>&lt;P&gt;Here's the article I alluded to above:&amp;nbsp;&lt;A href="https://docs.microsoft.com/en-us/power-bi/guidance/star-schema" target="_blank"&gt;Understand star schema and the importance for Power BI - Power BI | Microsoft Docs&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 15:40:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-DATEDIFF-in-measure/m-p/1543427#M30438</guid>
      <dc:creator>daxer-almighty</dc:creator>
      <dc:date>2020-12-10T15:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using DATEDIFF in measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-DATEDIFF-in-measure/m-p/1543777#M30456</link>
      <description>&lt;P&gt;Thank you. The Dax you provided works as a intented. I tried adding an additional filter in the FILTER using LOOKUPVALUE instead of RELATE to connect a 'Refit' table that also has an 'OpenedDate' column in an attempt to filter stores that have gone thru a refit as well. This time however the code nolonger seems to work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Sales Filter =&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;VAR CurrentYear_ =&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;YEAR ( MAX ( DateT[Date] ) ) // This could also be: VAR CurrentYear_ = MAX(DateT[Year]) &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;RETURN&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;CALCULATE (&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SUM ( Sales[sale] ),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FILTER ( Sales, &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; YEAR ( RELATED ( Stores[OpenedDate] ) ) &amp;lt;&amp;gt; currentYear_ &amp;amp;&amp;amp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; YEAR ( LOOKUPVALUE( Refit[OpenedDate], Refit[StoreID], Sales[StoreID] ) &amp;lt;&amp;gt; currentYear_ &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; )&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 10 Dec 2020 18:26:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-DATEDIFF-in-measure/m-p/1543777#M30456</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-12-10T18:26:57Z</dc:date>
    </item>
    <item>
      <title>Re: Using DATEDIFF in measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-DATEDIFF-in-measure/m-p/1543844#M30459</link>
      <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code above is missing a closing parenthesis. Not sure if that's&amp;nbsp; a typo when copying it here or if it is the actual problem.&lt;/P&gt;
&lt;P&gt;Do make sure you build the condition correctly according to what you want. Right now you are selecting stores that &lt;STRONG&gt;both&lt;/STRONG&gt; opened &lt;STRONG&gt;AND&lt;/STRONG&gt; went thru a refit&amp;nbsp; in another year.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Please mark the question solved when done and consider &lt;FONT color="#FF9900"&gt;giving a thumbs up if posts are helpful.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;Contact me privately for support with any larger-scale BI needs, tutoring, etc.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Cheers&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 20:48:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-DATEDIFF-in-measure/m-p/1543844#M30459</guid>
      <dc:creator>AlB</dc:creator>
      <dc:date>2020-12-10T20:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: Using DATEDIFF in measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-DATEDIFF-in-measure/m-p/1546227#M30540</link>
      <description>&lt;P&gt;Thanks so much! It now works as attended.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 20:31:24 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-DATEDIFF-in-measure/m-p/1546227#M30540</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-12-11T20:31:24Z</dc:date>
    </item>
  </channel>
</rss>

