<?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: STOCK ON HAND TRACING &amp;amp; VALUE CALCULATION in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/STOCK-ON-HAND-TRACING-amp-VALUE-CALCULATION/m-p/1332081#M23599</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="253083" data-lia-user-login="Nasir_Arslan35" class="lia-mention lia-mention-user"&gt;Nasir_Arslan35&lt;/a&gt; -&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Create a date table (using CALENDARAUTO() or something similar), then make a relationship between the date table and Order Date.&amp;nbsp; The DAX would then change to look like this, and you should get a value for every day:, even at the individual stock level.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;SOH = CALCULATE(
     SUM('STOCK MAPPING'[Trans QTY]), 
     FILTER(
     ALL(DateTab[Date),
        (DateTab[Date])&amp;lt;=MAX(DateTab[Date])
)
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the current value, you might want to create that as a calculated column on the Stock Mapping table, so that it works at all aggregation levels. Something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;//Calculated Column
Current Value = LOOKUPVALUE(ValueTable[Current Value], ValueTable[SKU], 'Stock Mapping'[SKU])

//Then your measure becomes
CALCULATE (
   SUM ( 'Stock Mapping'[Trans QTY] * 'Stock Mapping'[Current Value] )
   FILTER (ALL(DateTab), DateTab[Date] &amp;lt;= MAX(DateTab[Date])
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this doesn't work for you, please share some sample data, model structure and/or sample pbix file for further assistance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps&lt;/P&gt;
&lt;P&gt;David&lt;/P&gt;</description>
    <pubDate>Fri, 28 Aug 2020 13:04:04 GMT</pubDate>
    <dc:creator>dedelman_clng</dc:creator>
    <dc:date>2020-08-28T13:04:04Z</dc:date>
    <item>
      <title>STOCK ON HAND TRACING &amp; VALUE CALCULATION</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/STOCK-ON-HAND-TRACING-amp-VALUE-CALCULATION/m-p/1331932#M23592</link>
      <description>&lt;P&gt;Hi BI community,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i've a data set approx. 450k lines from which i need to map the inventory history. I've used the following code for the measure and it displays accurate values.&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;SOH = CALCULATE(&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;SUM('STOCK MAPPING'[Trans QTY]), &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;FILTER(&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;ALL('STOCK MAPPING'[Order Date]),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;('STOCK MAPPING'[Order Date])&amp;lt;=MAX('STOCK MAPPING'[Order Date])&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;However, for individual SKUs the stock values are only populated against the dates on which trasactions were registered. Secondly, i need to create a variable measure where stock on hand at each date between 2009 to present is multiplied with a standard unit cost (current one from a different table).&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Any suggestions please.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 28 Aug 2020 11:45:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/STOCK-ON-HAND-TRACING-amp-VALUE-CALCULATION/m-p/1331932#M23592</guid>
      <dc:creator>Nasir_Arslan35</dc:creator>
      <dc:date>2020-08-28T11:45:52Z</dc:date>
    </item>
    <item>
      <title>Re: STOCK ON HAND TRACING &amp; VALUE CALCULATION</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/STOCK-ON-HAND-TRACING-amp-VALUE-CALCULATION/m-p/1332081#M23599</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="253083" data-lia-user-login="Nasir_Arslan35" class="lia-mention lia-mention-user"&gt;Nasir_Arslan35&lt;/a&gt; -&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Create a date table (using CALENDARAUTO() or something similar), then make a relationship between the date table and Order Date.&amp;nbsp; The DAX would then change to look like this, and you should get a value for every day:, even at the individual stock level.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;SOH = CALCULATE(
     SUM('STOCK MAPPING'[Trans QTY]), 
     FILTER(
     ALL(DateTab[Date),
        (DateTab[Date])&amp;lt;=MAX(DateTab[Date])
)
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the current value, you might want to create that as a calculated column on the Stock Mapping table, so that it works at all aggregation levels. Something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;//Calculated Column
Current Value = LOOKUPVALUE(ValueTable[Current Value], ValueTable[SKU], 'Stock Mapping'[SKU])

//Then your measure becomes
CALCULATE (
   SUM ( 'Stock Mapping'[Trans QTY] * 'Stock Mapping'[Current Value] )
   FILTER (ALL(DateTab), DateTab[Date] &amp;lt;= MAX(DateTab[Date])
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this doesn't work for you, please share some sample data, model structure and/or sample pbix file for further assistance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps&lt;/P&gt;
&lt;P&gt;David&lt;/P&gt;</description>
      <pubDate>Fri, 28 Aug 2020 13:04:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/STOCK-ON-HAND-TRACING-amp-VALUE-CALCULATION/m-p/1332081#M23599</guid>
      <dc:creator>dedelman_clng</dc:creator>
      <dc:date>2020-08-28T13:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: STOCK ON HAND TRACING &amp; VALUE CALCULATION</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/STOCK-ON-HAND-TRACING-amp-VALUE-CALCULATION/m-p/1333651#M23684</link>
      <description>&lt;P&gt;For datetime calculations, you need to have a proper Dates table. Also, storing everything inside one big table should be avoided at all costs. There are too many good reasons for this to enlarge upon right now. Please create a good star-schema model with a datetime dimension and it'll all be much, much easier. Not to mention - much faster. And DAX will be much more readable/understandable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When you have the Dates dimension, you can write:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;// 'Stock Mapping' should be a hidden fact table.
// 'Dates' should be a date dimension that joins to
// [Order Date] in Stock Mapping.

SOH =
var __maxOrderDate = MAX( 'Dates'[Date] )
var __result =
    CALCULATE(
        SUM( 'STOCK MAPPING'[Trans QTY] ),
        // This code will work if 'Dates'
        // is marked as a date table in
        // the model. If it's not, then
        // you have to add ALL( 'Dates' )
        // as the last argument of CALCULATE.
        'Dates'[Date] &amp;lt;= __maxOrderDate
    )
RETURN
    __result&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 29 Aug 2020 17:26:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/STOCK-ON-HAND-TRACING-amp-VALUE-CALCULATION/m-p/1333651#M23684</guid>
      <dc:creator>daxer-almighty</dc:creator>
      <dc:date>2020-08-29T17:26:51Z</dc:date>
    </item>
    <item>
      <title>Re: STOCK ON HAND TRACING &amp; VALUE CALCULATION</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/STOCK-ON-HAND-TRACING-amp-VALUE-CALCULATION/m-p/2094012#M47705</link>
      <description>&lt;P&gt;When I filter per product and per Store it gives the last stock even it before the current date of SOH, so how can we calculate all stocks of last update even if filtered by product and retail&lt;BR /&gt;I tried with removefilters/ALL it works with product but did not work with retails and give me previous dates if the branch do not have date like last update ?&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 10:32:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/STOCK-ON-HAND-TRACING-amp-VALUE-CALCULATION/m-p/2094012#M47705</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-09-23T10:32:35Z</dc:date>
    </item>
  </channel>
</rss>

