<?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 Get the previous value calculated with ALLEXCEPT in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-the-previous-value-calculated-with-ALLEXCEPT/m-p/2118768#M48554</link>
    <description>&lt;P&gt;Hi everyone. I've got this table:&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;UL&gt;&lt;LI&gt;ProdID is the key: it represents the production order&lt;/LI&gt;&lt;LI&gt;Date represents the date. In this case from 28th to 30 september&lt;/LI&gt;&lt;LI&gt;Product is the name of the product&lt;/LI&gt;&lt;LI&gt;Total Qty is the total number of pieces that must be produced in the current production order&lt;/LI&gt;&lt;LI&gt;Produced Pieces is the quantity produce. It represents to which point we are with the production: it is a value that is increased as pieces are produced&lt;/LI&gt;&lt;LI&gt;MaxProducedPiecesToday represents the total quantity produced in each date, and it is calculated as the maximum of ProducedPieces for each date, using ALLEXCEPT, as explained in the picture&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;My purpose is to calculate the number of Pieces Produced Today, given by the maximum of pieces produced today minus the maximum of pieces produced in the previous date, that &lt;STRONG&gt;might not be the day immediately preceding&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you help me? Thanks in advance. Here is the PBIX file:&amp;nbsp;&lt;A href="https://www.dropbox.com/s/2h9avwap7xy2qw1/Production%20order.pbix?dl=0" target="_blank"&gt;https://www.dropbox.com/s/2h9avwap7xy2qw1/Production%20order.pbix?dl=0&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 06 Oct 2021 10:25:25 GMT</pubDate>
    <dc:creator>mtrevisiol</dc:creator>
    <dc:date>2021-10-06T10:25:25Z</dc:date>
    <item>
      <title>Get the previous value calculated with ALLEXCEPT</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-the-previous-value-calculated-with-ALLEXCEPT/m-p/2118768#M48554</link>
      <description>&lt;P&gt;Hi everyone. I've got this table:&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;UL&gt;&lt;LI&gt;ProdID is the key: it represents the production order&lt;/LI&gt;&lt;LI&gt;Date represents the date. In this case from 28th to 30 september&lt;/LI&gt;&lt;LI&gt;Product is the name of the product&lt;/LI&gt;&lt;LI&gt;Total Qty is the total number of pieces that must be produced in the current production order&lt;/LI&gt;&lt;LI&gt;Produced Pieces is the quantity produce. It represents to which point we are with the production: it is a value that is increased as pieces are produced&lt;/LI&gt;&lt;LI&gt;MaxProducedPiecesToday represents the total quantity produced in each date, and it is calculated as the maximum of ProducedPieces for each date, using ALLEXCEPT, as explained in the picture&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;My purpose is to calculate the number of Pieces Produced Today, given by the maximum of pieces produced today minus the maximum of pieces produced in the previous date, that &lt;STRONG&gt;might not be the day immediately preceding&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you help me? Thanks in advance. Here is the PBIX file:&amp;nbsp;&lt;A href="https://www.dropbox.com/s/2h9avwap7xy2qw1/Production%20order.pbix?dl=0" target="_blank"&gt;https://www.dropbox.com/s/2h9avwap7xy2qw1/Production%20order.pbix?dl=0&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Oct 2021 10:25:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-the-previous-value-calculated-with-ALLEXCEPT/m-p/2118768#M48554</guid>
      <dc:creator>mtrevisiol</dc:creator>
      <dc:date>2021-10-06T10:25:25Z</dc:date>
    </item>
    <item>
      <title>Re: Get the previous value calculated with ALLEXCEPT</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-the-previous-value-calculated-with-ALLEXCEPT/m-p/2120283#M48593</link>
      <description>&lt;P&gt;This should get you the value from the previous date.&amp;nbsp; You can then work out the subtraction. Please test with more products and different date setups.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;NewColumn = VAR _prodID = Query[ProdID]
VAR _date = Query[Date]
VAR _fromDate = CALCULATE(MAX(Query[Date]), FILTER(Query, Query[Date] &amp;lt; _date  &amp;amp;&amp;amp; Query[ProdID] = _prodID))

RETURN
CALCULATE(MAX(Query[MaxProducedPcsToday]), FILTER(Query, Query[Date] = _fromDate &amp;amp;&amp;amp; Query[ProdID] = _prodID))&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 01:47:29 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-the-previous-value-calculated-with-ALLEXCEPT/m-p/2120283#M48593</guid>
      <dc:creator>HotChilli</dc:creator>
      <dc:date>2021-10-07T01:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: Get the previous value calculated with ALLEXCEPT</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-the-previous-value-calculated-with-ALLEXCEPT/m-p/2120765#M48598</link>
      <description>&lt;P&gt;Thanks for help&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="81111" data-lia-user-login="HotChilli" class="lia-mention lia-mention-user"&gt;HotChilli&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did it by creating this column:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Max precedente = &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var max_precedente = CALCULATE (&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;MAX ( Query[ProducedPcs] ),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;FILTER (&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; ALL ( Query ),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Query[Date] &amp;lt; EARLIER ( Query[Date] )&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;amp;&amp;amp; Query[MOId] = EARLIER(Query[ProdID])&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;&lt;SPAN&gt;RETURN IF(max_precedente&amp;gt;0, max_precedente, 0)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 07 Oct 2021 06:44:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-the-previous-value-calculated-with-ALLEXCEPT/m-p/2120765#M48598</guid>
      <dc:creator>mtrevisiol</dc:creator>
      <dc:date>2021-10-07T06:44:12Z</dc:date>
    </item>
  </channel>
</rss>

