<?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: DAX: How to Multiply the Sum of a Column by the Maximum Value of Another Column in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-How-to-Multiply-the-Sum-of-a-Column-by-the-Maximum-Value-of/m-p/3795085#M148310</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a fact table like that:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The aspected result are:&lt;/P&gt;&lt;P&gt;- If i select the date of 01/01/2024 on the report slicer:&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;The following result, boot by product and total:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;-&amp;nbsp;If i select the date of 02/02/2024 on the report slicer:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;-&amp;nbsp;If i select the date of 03/03/2024 on the report slicer:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;-&amp;nbsp;If i select the date of 04/04/2024 on the report slicer:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;the reasoning of this last case, but the same applies to the previous ones is:&lt;BR /&gt;- The StockQty column must be the sum of the movements from the dawn of time until the selected date (04/04/2024). Which, for the product x is 100 (i.e. the sum of its movements up to the date: 100+20+30-50), for the product Y it is 50 (100-80+20+10).&lt;BR /&gt;- The LastStockUnitPrice column is, for each product x, the last unit cost valid on the date. For the product, the last valid cost is the one corresponding to the record of the original dataset as of 04/04/2024, i.e. 16, for the product Y 22. Obviously this measurement on the total line makes no sense.&lt;BR /&gt;- The StockValueBaseTable column is the product, per row, of the two previous values. This is the real value I want to get. On the total line, the result to be obtained is not the product of the two previous measurements on the total line, but rather the sum of the products by product.&lt;/P&gt;</description>
    <pubDate>Wed, 27 Mar 2024 19:57:20 GMT</pubDate>
    <dc:creator>MMPowerBI</dc:creator>
    <dc:date>2024-03-27T19:57:20Z</dc:date>
    <item>
      <title>DAX: How to Multiply the Sum of a Column by the Maximum Value of Another Column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-How-to-Multiply-the-Sum-of-a-Column-by-the-Maximum-Value-of/m-p/3766986#M147072</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;thanks in advance for your support.&lt;/P&gt;&lt;P&gt;I'm facing a complex calculation with DAX that I'm not able to solve and I need support.&lt;/P&gt;&lt;P&gt;I have a fact table of inventory movements composed as follows:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ProductCode&lt;/TD&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;TD&gt;Quantity&lt;/TD&gt;&lt;TD&gt;UnitCost&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;TD&gt;01/01/2024&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;TD&gt;01/02/2024&lt;/TD&gt;&lt;TD&gt;-5&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;TD&gt;01/03/2024&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;y&lt;/TD&gt;&lt;TD&gt;01/01/2024&lt;/TD&gt;&lt;TD&gt;30&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;y&lt;/TD&gt;&lt;TD&gt;01/02/2024&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;y&lt;/TD&gt;&lt;TD&gt;01/03/2024&lt;/TD&gt;&lt;TD&gt;-20&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The quantity in stock of a product at a given date is determined as the sum of the Quantity column from the point of time until the selected date.&lt;/P&gt;&lt;P&gt;On the other hand, the value of the inventory is to be determined as the product of the quantity in stock on the date (defined as above) for the last valid UnitCost with respect to the selected date (obviously per product, not the last valid cost ever).&lt;/P&gt;&lt;P&gt;For example: if I want to see the stock as of 02/03/2024 I would expect this result:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Product&lt;/TD&gt;&lt;TD&gt;Stock Quantity&lt;/TD&gt;&lt;TD&gt;Stock Value&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;TD&gt;25&lt;/TD&gt;&lt;TD&gt;175&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;y&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;80&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where:&lt;/P&gt;&lt;P&gt;StockValue of product x need to be&amp;nbsp;multiplying the sum of the quantities in stock up to the desired date and the ultimate unit cost with respect to the selected date. In the case under analysis, the date of 02/03/2024 has been selected, there is no cost on this date because the last movement is the previous day so that is the cost to be considered to value the entire stock.&lt;/P&gt;&lt;P&gt;The same reasoning for the stock of product y.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would need to write a measure that can calculate this stock value. The desire is to have a measure that works both if it is used in a PBI table that has the product as a row attribute but also as a total.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can any of you give me some suggestions on how to do this?&lt;/P&gt;&lt;P&gt;Thank you so much in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 15:01:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-How-to-Multiply-the-Sum-of-a-Column-by-the-Maximum-Value-of/m-p/3766986#M147072</guid>
      <dc:creator>MMPowerBI</dc:creator>
      <dc:date>2024-03-15T15:01:07Z</dc:date>
    </item>
    <item>
      <title>Re: DAX: How to Multiply the Sum of a Column by the Maximum Value of Another Column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-How-to-Multiply-the-Sum-of-a-Column-by-the-Maximum-Value-of/m-p/3767314#M147101</link>
      <description>&lt;P&gt;That seems to be highly confusing. I played with your sample data a bit and here is what I came up with instead.&amp;nbsp; Feel free to modify as needed&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 17:36:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-How-to-Multiply-the-Sum-of-a-Column-by-the-Maximum-Value-of/m-p/3767314#M147101</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2024-03-15T17:36:08Z</dc:date>
    </item>
    <item>
      <title>Re: DAX: How to Multiply the Sum of a Column by the Maximum Value of Another Column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-How-to-Multiply-the-Sum-of-a-Column-by-the-Maximum-Value-of/m-p/3795050#M148305</link>
      <description>&lt;P&gt;Hi Ibendlin,&lt;/P&gt;&lt;P&gt;thank for reply.&lt;/P&gt;&lt;P&gt;The proposed solution is not the aspected one.&lt;/P&gt;&lt;P&gt;I probably didn't explain myself well.&lt;/P&gt;&lt;P&gt;let's consider the row dated 03/02/2024 in your example dataset.&lt;/P&gt;&lt;P&gt;in this case the quantity in stock is actually correct, it must be the sum of the quantities up to that moment (therefore 10-5=5). The value, however, must be calculated by multiplying the previously calculated quantity (therefore 5) with the last unit cost valid on that date (in this case the last valid cost for product x on the date of 02/03/2024 is the one that, in the original table I posted, refers to 02/01/2024 which is 6). So as a stock value on 02/03/2024 I would have expected to see 30 (5*6).&lt;BR /&gt;Furthermore, the calculation must be done per product because the unit value must be the latest for each product multiplied by the quantity in stock of the specific product).&lt;BR /&gt;On the total I would therefore expect to find the following value:&lt;BR /&gt;Stock value total = StockQtyX*LastUnitPriceX+StockQtyY*LastStockPriceY&lt;BR /&gt;Where:&lt;BR /&gt;- StockQtyX is the sum of the quantities of product&lt;BR /&gt;- LastUnitPriceX is the last unit price valid on the selected date (6 in the previous example)&lt;BR /&gt;Same considerations for Y.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to sketch a solution like this:&lt;/P&gt;&lt;P&gt;- Measure:&amp;nbsp;&lt;SPAN&gt;fx_StockUnitPrice =&lt;/SPAN&gt; &lt;SPAN&gt;MIN&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'Movimenti'&lt;/SPAN&gt;&lt;SPAN&gt;[Price]&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- Measure:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;LastStockUnitPrice = &lt;/SPAN&gt;&lt;SPAN&gt;var&lt;/SPAN&gt;&lt;SPAN&gt; _SelectedDate = &lt;/SPAN&gt;&lt;SPAN&gt;MAX&lt;/SPAN&gt;&lt;SPAN&gt;('Calendario'[Data]) &lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;RETURN&lt;/SPAN&gt; &lt;SPAN&gt;CALCULATE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;LASTNONBLANKVALUE&lt;/SPAN&gt;&lt;SPAN&gt;('Movimenti'[Data], 'Movimenti'[fx_StockUnitPrice]), 'Movimenti'[Data]&amp;lt;= _SelectedDate)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;SPAN&gt;- Measure:&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;StockValueBaseTable =&lt;/SPAN&gt; &lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;MainTable&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;SUMMARIZE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'Movimenti'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;Movimenti&lt;/SPAN&gt;&lt;SPAN&gt;[Prodotto]&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"LastStockUnitPrice"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;[LastStockUnitPrice]&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"Stock Qty"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;[Stock qty]&lt;/SPAN&gt;&lt;SPAN&gt;)&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;SUMX&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;MainTable&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;[LastStockUnitPrice]&lt;/SPAN&gt;&lt;SPAN&gt;*&lt;/SPAN&gt;&lt;SPAN&gt;[Stock Qty]&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Where table movimenti is the fact table i posted in the first post.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;That solution works fine in a test case with few data.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;When I implement that solution in the real case with over 50M data (There will be over 600M when fully operational) this solution goes in "exceded resource limits" of the powerBI report.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Is there a way to achieve the same result more efficiently?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Thanks in advance&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 27 Mar 2024 19:19:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-How-to-Multiply-the-Sum-of-a-Column-by-the-Maximum-Value-of/m-p/3795050#M148305</guid>
      <dc:creator>MMPowerBI</dc:creator>
      <dc:date>2024-03-27T19:19:54Z</dc:date>
    </item>
    <item>
      <title>Re: DAX: How to Multiply the Sum of a Column by the Maximum Value of Another Column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-How-to-Multiply-the-Sum-of-a-Column-by-the-Maximum-Value-of/m-p/3795061#M148306</link>
      <description>&lt;P&gt;Please provide sample data &lt;STRONG&gt;that fully covers your issue&lt;/STRONG&gt;.&lt;BR /&gt;Please show the expected outcome based on the sample data you provided.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 19:38:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-How-to-Multiply-the-Sum-of-a-Column-by-the-Maximum-Value-of/m-p/3795061#M148306</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2024-03-27T19:38:30Z</dc:date>
    </item>
    <item>
      <title>Re: DAX: How to Multiply the Sum of a Column by the Maximum Value of Another Column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-How-to-Multiply-the-Sum-of-a-Column-by-the-Maximum-Value-of/m-p/3795085#M148310</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a fact table like that:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The aspected result are:&lt;/P&gt;&lt;P&gt;- If i select the date of 01/01/2024 on the report slicer:&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;The following result, boot by product and total:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;-&amp;nbsp;If i select the date of 02/02/2024 on the report slicer:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;-&amp;nbsp;If i select the date of 03/03/2024 on the report slicer:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;-&amp;nbsp;If i select the date of 04/04/2024 on the report slicer:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;the reasoning of this last case, but the same applies to the previous ones is:&lt;BR /&gt;- The StockQty column must be the sum of the movements from the dawn of time until the selected date (04/04/2024). Which, for the product x is 100 (i.e. the sum of its movements up to the date: 100+20+30-50), for the product Y it is 50 (100-80+20+10).&lt;BR /&gt;- The LastStockUnitPrice column is, for each product x, the last unit cost valid on the date. For the product, the last valid cost is the one corresponding to the record of the original dataset as of 04/04/2024, i.e. 16, for the product Y 22. Obviously this measurement on the total line makes no sense.&lt;BR /&gt;- The StockValueBaseTable column is the product, per row, of the two previous values. This is the real value I want to get. On the total line, the result to be obtained is not the product of the two previous measurements on the total line, but rather the sum of the products by product.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 19:57:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-How-to-Multiply-the-Sum-of-a-Column-by-the-Maximum-Value-of/m-p/3795085#M148310</guid>
      <dc:creator>MMPowerBI</dc:creator>
      <dc:date>2024-03-27T19:57:20Z</dc:date>
    </item>
  </channel>
</rss>

