<?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: Calculate the stock cost for items that haven't been shipped for 1 year in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-the-stock-cost-for-items-that-haven-t-been-shipped-for/m-p/3448720#M131306</link>
    <description>&lt;P&gt;This code&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Cout Stock = 
    CALCULATE
    (
        SUM(ILECosts[Stock Cost]), 
        FILTER(ALL(ILECosts), ILECosts[Posting Date] &amp;lt;= MAX(DIM_Date[Date]))
    )&lt;/LI-CODE&gt;
&lt;P&gt;is questionable and should be refactored.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Cout Stock = 
    var md = MAX(DIM_Date[Date])
    RETURN CALCULATE
    (
        SUM(ILECosts[Stock Cost]), 
        ILECosts[Posting Date] &amp;lt;= md
    )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot). Leave out anything not related to the issue. &lt;BR /&gt;If you are unsure how to do that please refer to &lt;A href="https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216" target="_blank"&gt;https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216&lt;/A&gt; &lt;BR /&gt;Please show the expected outcome based on the sample data you provided. &lt;BR /&gt;&lt;BR /&gt;If you want to get answers faster please refer to &lt;A href="https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523" target="_blank"&gt;https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Sep 2023 00:30:32 GMT</pubDate>
    <dc:creator>lbendlin</dc:creator>
    <dc:date>2023-09-27T00:30:32Z</dc:date>
    <item>
      <title>Calculate the stock cost for items that haven't been shipped for 1 year</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-the-stock-cost-for-items-that-haven-t-been-shipped-for/m-p/3446106#M131113</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to calculate the stock cost value of items that have not been shipped for 1 year.&lt;/P&gt;&lt;P&gt;Here's my (simplified) data model. ILECosts are the cost of each Item Ledger Entry in my ERP.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;The "Cout stock" measure calculates the daily stock cost. Its values are correct, I checked them separately with an SQL query. Here's the DAX measure code:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Cout Stock = 
    CALCULATE
    (
        SUM(ILECosts[Stock Cost]), 
        FILTER(ALL(ILECosts), ILECosts[Posting Date] &amp;lt;= MAX(DIM_Date[Date]))
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to create another measure that can filter the previous one, by only calculating the &lt;STRONG&gt;cost of Item Ledger Entries for items that have not been shipped for more than one year before the selected date range. A shipped Item Ledger Entry is defined by&amp;nbsp;&lt;SPAN&gt;ILECosts&lt;/SPAN&gt;&lt;SPAN&gt;[Document Type]&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;1.&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here's an example of what I tried, but it's obviously wrong and too simplistic. I think I should summarize a subset of data by ILECosts[Item No_], to compute what has not been shipped for one year prior to the selected date range, but I don't understand how to do it.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Cout Stock sans expéd depuis 1 an = 
VAR Year_1 = DATEADD(DIM_Date[Date], -1, YEAR)
    
VAR ILEShippingCostsOLD = 
    CALCULATETABLE( 
        ILECosts,
        FILTER ( ALL ( ILECosts ), ILECosts[Posting Date] &amp;lt;= MAX ( DIM_Date[Date] ) ),
        FILTER ( ALL ( ILECosts ), ILECosts[Document Type] = 1 )
        )
VAR MaxShippingDateOLD = MAXX
(
    ILEShippingCostsOLD,
    ILECosts[Posting Date]
)
VAR MaxShippingDate = 
(
    CALCULATE
    (
        MAX(ILECosts[Posting Date]), 
        FILTER ( ALL ( ILECosts ), ILECosts[Posting Date] &amp;lt;= MAX ( DIM_Date[Date] ) ),
        FILTER ( ALL ( ILECosts ), ILECosts[Document Type] = 1 )
    )
)
    
VAR x = 
    --IF (MaxShippingDate &amp;lt;= Year_1, 1, 0
        CALCULATE
        (
            [Cout Stock],
            FILTER ( (ILECosts), ILECosts[Posting Date] &amp;gt;= MaxShippingDate )
        )
    --)
RETURN x&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll upload the .pbix file if necessary. Thanks in advance for any hint.&lt;/P&gt;&lt;P&gt;PS: my first post here. I hope everything is clear and clean enough!&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2023 14:18:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-the-stock-cost-for-items-that-haven-t-been-shipped-for/m-p/3446106#M131113</guid>
      <dc:creator>MikeRales</dc:creator>
      <dc:date>2023-09-25T14:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the stock cost for items that haven't been shipped for 1 year</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-the-stock-cost-for-items-that-haven-t-been-shipped-for/m-p/3448720#M131306</link>
      <description>&lt;P&gt;This code&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Cout Stock = 
    CALCULATE
    (
        SUM(ILECosts[Stock Cost]), 
        FILTER(ALL(ILECosts), ILECosts[Posting Date] &amp;lt;= MAX(DIM_Date[Date]))
    )&lt;/LI-CODE&gt;
&lt;P&gt;is questionable and should be refactored.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Cout Stock = 
    var md = MAX(DIM_Date[Date])
    RETURN CALCULATE
    (
        SUM(ILECosts[Stock Cost]), 
        ILECosts[Posting Date] &amp;lt;= md
    )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot). Leave out anything not related to the issue. &lt;BR /&gt;If you are unsure how to do that please refer to &lt;A href="https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216" target="_blank"&gt;https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216&lt;/A&gt; &lt;BR /&gt;Please show the expected outcome based on the sample data you provided. &lt;BR /&gt;&lt;BR /&gt;If you want to get answers faster please refer to &lt;A href="https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523" target="_blank"&gt;https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2023 00:30:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-the-stock-cost-for-items-that-haven-t-been-shipped-for/m-p/3448720#M131306</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2023-09-27T00:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the stock cost for items that haven't been shipped for 1 year</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-the-stock-cost-for-items-that-haven-t-been-shipped-for/m-p/3449107#M131327</link>
      <description>&lt;P&gt;Thanks for the reply.&lt;/P&gt;&lt;P&gt;My formula for "Cout stock" is really what I need. I want the cumulative sum for all item ledger entries, from the very first ILE, up to the chosen date. I added to the .pbix the formula you suggested so you can see the difference.&lt;/P&gt;&lt;P&gt;Here's the&amp;nbsp;&lt;A href="https://etiluxbe-my.sharepoint.com/:u:/g/personal/mal_etilux_be/Ef9UBKWtuY1FrT8MYY5vzsUB1cDIiQnOzoFe_Ictos-o_g?e=KRfswR" target="_self"&gt;link to the .pbix file&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I want 2 things:&lt;/P&gt;&lt;P&gt;- a formula that calculates the cost for the Item Ledger Entries of "Item No_" that have not been shipped for more than 1 year before the selected date range.&lt;/P&gt;&lt;P&gt;An ILE for a shipped "Item No_" matches this criteria:&amp;nbsp;&lt;STRONG&gt;&lt;SPAN&gt;ILECosts&lt;/SPAN&gt;&lt;SPAN&gt;[Document Type]&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;1.&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The 1 year period must be variable (1, 2 or 3years).&lt;/P&gt;&lt;P&gt;- a chart that shows the "Cout stock" formula and the new one. I added this chart in the .pbix file.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2023 07:03:19 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-the-stock-cost-for-items-that-haven-t-been-shipped-for/m-p/3449107#M131327</guid>
      <dc:creator>MikeRales</dc:creator>
      <dc:date>2023-09-27T07:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the stock cost for items that haven't been shipped for 1 year</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-the-stock-cost-for-items-that-haven-t-been-shipped-for/m-p/3449888#M131382</link>
      <description>&lt;LI-CODE lang="markup"&gt;I want the cumulative sum for all item ledger entries, from the very first ILE, up to the chosen date.&lt;/LI-CODE&gt;
&lt;P&gt;Define "very first".&amp;nbsp; very first based on the user filters, or very first ignoring all filters?&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Cout Stock = 
    var mxd=MAX(DIM_Date[Date])
    return CALCULATE
    (
        SUM(ILECosts[Stock Cost]), 
        ALLSELECTED(DIM_Date[Date]),
        ILECosts[Posting Date] &amp;lt;= mxd
    )&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 27 Sep 2023 13:46:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-the-stock-cost-for-items-that-haven-t-been-shipped-for/m-p/3449888#M131382</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2023-09-27T13:46:32Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the stock cost for items that haven't been shipped for 1 year</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-the-stock-cost-for-items-that-haven-t-been-shipped-for/m-p/3449930#M131384</link>
      <description>&lt;P&gt;Very first chronologicaly, ignoring all filters.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2023 14:08:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-the-stock-cost-for-items-that-haven-t-been-shipped-for/m-p/3449930#M131384</guid>
      <dc:creator>MikeRales</dc:creator>
      <dc:date>2023-09-27T14:08:16Z</dc:date>
    </item>
  </channel>
</rss>

