<?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: Calculating Sales for current year or month by products older than 5 years depending on date context in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-Sales-for-current-year-or-month-by-products-older/m-p/2512255#M69719</link>
    <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt; , Not very clear&lt;/P&gt;
&lt;P&gt;All 5 year sales&lt;/P&gt;
&lt;P&gt;CALCULATE([Sales], Filter(all(Table), [CounterNSR]=1) )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Selected period sales&amp;nbsp; = [Sales]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Select period sales only from 5 years&lt;/P&gt;
&lt;P&gt;CALCULATE([Sales], Filter((Table), [CounterNSR]=1) )&lt;/P&gt;</description>
    <pubDate>Fri, 13 May 2022 05:56:23 GMT</pubDate>
    <dc:creator>amitchandak</dc:creator>
    <dc:date>2022-05-13T05:56:23Z</dc:date>
    <item>
      <title>Calculating Sales for current year or month by products older than 5 years depending on date context</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-Sales-for-current-year-or-month-by-products-older/m-p/2512153#M69712</link>
      <description>&lt;P&gt;Hi!&amp;nbsp;&lt;BR /&gt;I've made a &lt;A href="https://community.powerbi.com/t5/DAX-Commands-and-Tips/Showing-Products-between-two-dates-depending-on-Cal-Filter/m-p/2450517#M65930" target="_self"&gt;previous post&lt;/A&gt;&amp;nbsp;about this but unfortunatley the problem remains and is not as dynamic as I need it to be.&amp;nbsp;&lt;BR /&gt;I have a datasets that's around 3gb so will not be able to provide full dataset but can try to provide examples if necessary.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I have a Fact Table with sales and a Products table with released for salesdate. I need to create a dynamic way to filter products that have a ReleasedforSalesdate that is -5 years old in between (firstdate,Year,-5) &amp;amp; lastdate(firstdate,year, -5) of the sliced/selected calenderdate. I've tried to create a massive calculated column to act as a flag but have not been able to connect a dynamic filter to show the sales only for the selected period.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;STRONG&gt;Calculated column is a link table between Fact and Product table:&amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;CounterNSR= IF&lt;/SPAN&gt;&lt;SPAN&gt;( &lt;/SPAN&gt;&lt;SPAN&gt;ReleasedforSalesDate&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt; &lt;/SPAN&gt;&lt;SPAN&gt;[LastDateInMonth]&lt;/SPAN&gt;&lt;SPAN&gt; -&lt;/SPAN&gt;&lt;SPAN&gt;1826&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;)&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;SalesforProductslessthan5=&amp;nbsp;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;CALCULATE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;[Sales]&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;[CounterNSR]&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;STRONG&gt;NewSalesratio=&amp;nbsp;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Calculate&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;DIVIDE&lt;/SPAN&gt;&lt;SPAN&gt;( &lt;/SPAN&gt;&lt;SPAN&gt;[NewSales]&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;[TotalSales]&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Expected result:&amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;If I select year 2021 I want to see the invoiced sales for 2021 only for products that have a RFSD between 2016/01/01 - 2021/12/31. If I selected a month, (for e.g. March 2021) I only want to show products with a RFSD between 2016/03/01 - 2021/03/31.&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 13 May 2022 05:13:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-Sales-for-current-year-or-month-by-products-older/m-p/2512153#M69712</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-05-13T05:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Sales for current year or month by products older than 5 years depending on date context</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-Sales-for-current-year-or-month-by-products-older/m-p/2512255#M69719</link>
      <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt; , Not very clear&lt;/P&gt;
&lt;P&gt;All 5 year sales&lt;/P&gt;
&lt;P&gt;CALCULATE([Sales], Filter(all(Table), [CounterNSR]=1) )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Selected period sales&amp;nbsp; = [Sales]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Select period sales only from 5 years&lt;/P&gt;
&lt;P&gt;CALCULATE([Sales], Filter((Table), [CounterNSR]=1) )&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2022 05:56:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-Sales-for-current-year-or-month-by-products-older/m-p/2512255#M69719</guid>
      <dc:creator>amitchandak</dc:creator>
      <dc:date>2022-05-13T05:56:23Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Sales for current year or month by products older than 5 years depending on date context</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-Sales-for-current-year-or-month-by-products-older/m-p/2512357#M69726</link>
      <description>&lt;P&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="148838" data-lia-user-login="amitchandak" class="lia-mention lia-mention-user"&gt;amitchandak&lt;/a&gt;&amp;nbsp;and thank you for replying.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I've tried that measure but it's not working, could it be due to my datamodel connections?&amp;nbsp;&lt;BR /&gt;The table is returning sales for the products less than 5 year but returning sales alot larger than they should be. New sales is expected to be less than 20% but show 85% in current measure.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;The calculated column is consists of XX million rows where i've taken each itemnumber per historic month and returned 1 if the released for sales date is less than 5 years (-1825 days) in that month or 0 if not.&amp;nbsp;&lt;BR /&gt;The calculated column has an active connection to the sales table, an inactive to product (to bring in ReleasedforSalesdate) and an inactive to Date.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Could it be that the calender(orange) is not able to correctly iterate and filter Sales (Yellow) and NSRCounter (blue)?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;BR /&gt;&lt;BR /&gt;My estimated solution is supposed to filter the products on ReleasedforSalesdate depending on the current datecontext in my slicer( 2021 or 2021-01) for example and filter products that are less than 5 years. Then I want to calculate the current sales for those prodiucts in my selected date context (e.g sales for 2021-01 for products XXX)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2022 08:32:39 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-Sales-for-current-year-or-month-by-products-older/m-p/2512357#M69726</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-05-13T08:32:39Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Sales for current year or month by products older than 5 years depending on date context</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-Sales-for-current-year-or-month-by-products-older/m-p/2514970#M69897</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;// Let's assume that:
// 1. Dates (your proper calendar) is connected by 1-* to Purchases (fact)
//    on the field Purchase[PurchaseDate].
// 2. Products is a dim table that connected to your fact by 1-*
//    on Products[ProductID].
// 3. Your Products has a field Products[Release Date]. This field is not
//    connected to your calendar.
// Then you want to write a measure that will calculate
// the sales in the current period of products that have Release Date 
// within N years (in your case N = 5) back from the currently
// selected period of time. The measure should, of course, respond
// to any other selections in any other dimensions. Bear in mind that
// fact tables should always be hidden and slicing must always take
// place via dimensions. The only exceptions to this is degenerate
// dimensions. We'll make N a parameter in the measure.
//
// IF YOUR LOGIC WITH DATES IS DIFFERENT, PLEASE ADJUST ACCORDINGLY.

[Purchase Amount (-N yrs)] =
var YearsBack = 5 // change it accordingly
var ShiftedDates =
    // For this func to work, the selected period of time
    // from the calendar must be contiguous.
    DATEADD( Dates[Date], -YearsBack, YEAR )
var ShiftedStartDate =
    MINX( ShiftedDates, Dates[Date] )
var ShiftedEndDate =
    MAXX( ShiftedDates, Dates[Date] )
var ProductsWithReleaseDateWithinNYearsBack =
    CALCULATETABLE(
        DISTINCT( Products[ProductId] ),
        KEEPFILTERS( Products[Release Date] &amp;gt;= ShiftedStartDate ),
        KEEPFILTERS( Products[Release Date] &amp;lt;= ShiftedEndDate )
    )
var Result =
    CALCULATE(
        [Sales],
        ProductsWithReleaseDateWithinNYearsBack
    )
return
    Result&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 May 2022 10:33:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-Sales-for-current-year-or-month-by-products-older/m-p/2514970#M69897</guid>
      <dc:creator>daXtreme</dc:creator>
      <dc:date>2022-05-14T10:33:17Z</dc:date>
    </item>
  </channel>
</rss>

