<?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: Formula Battery With Previous Row and with MIN and MAX in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Formula-Battery-With-Previous-Row-and-with-MIN-and-MAX/m-p/4330886#M171915</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="796215" data-lia-user-login="dharmendars007" class="lia-mention lia-mention-user"&gt;dharmendars007&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;Thankyou for your answer!&lt;/P&gt;&lt;P&gt;But the formula gives an error:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 16 Dec 2024 13:33:27 GMT</pubDate>
    <dc:creator>PBINL</dc:creator>
    <dc:date>2024-12-16T13:33:27Z</dc:date>
    <item>
      <title>Formula Battery With Previous Row and with MIN and MAX</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Formula-Battery-With-Previous-Row-and-with-MIN-and-MAX/m-p/4330757#M171909</link>
      <description>&lt;P&gt;Good afternoon,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a question, I am looking for a formula for the contents of a battery. I have an 'in' column that is what comes into the battery and the 'out' column what goes out, in the 'solution' column I have the outcome of what should come from the DAX formula, I do not get the right outcome. It is important that the formula should never fall below 0 and never exceed 100, if the value falls below 0 it must continue to calculate with 0, no more can be extracted from a battery if it is completely empty.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The formula also needs to know what was in the battery in the row before and then continue calculating with that number.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there anyone who could help with a correct DAX formula?&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2024 12:08:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Formula-Battery-With-Previous-Row-and-with-MIN-and-MAX/m-p/4330757#M171909</guid>
      <dc:creator>PBINL</dc:creator>
      <dc:date>2024-12-16T12:08:37Z</dc:date>
    </item>
    <item>
      <title>Re: Formula Battery With Previous Row and with MIN and MAX</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Formula-Battery-With-Previous-Row-and-with-MIN-and-MAX/m-p/4330807#M171910</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="445451" data-lia-user-login="PBINL" class="lia-mention lia-mention-user"&gt;PBINL&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;To handle row-wise calculations where the cumulative sum respects boundaries (0 to 100), use the following pattern&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;Battery Solution = &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;VAR CurrentIndex = MAX('Table'[index])&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;VAR CurrentIn = MAX('Table'[In])&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;VAR CurrentOut = MAX('Table'[Out])&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;VAR PreviousBattery =&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;CALCULATE([Battery Solution], &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;FILTER('Table', 'Table'[index] = CurrentIndex - 1))&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;RETURN&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;MIN(100, MAX(0, PreviousBattery + CurrentIn - CurrentOut))&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;U&gt;&lt;STRONG&gt;If you find this helpful , please mark it as solution which will be helpful for others and Your Kudos/Likes &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt; are much appreciated!&lt;/STRONG&gt;&lt;/U&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank You&lt;/P&gt;&lt;P&gt;Dharmendar S&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.linkedin.com/in/dharmendar-s-b5b43463/" target="_blank" rel="noopener"&gt;&lt;SPAN&gt;LinkedIN&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2024 12:35:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Formula-Battery-With-Previous-Row-and-with-MIN-and-MAX/m-p/4330807#M171910</guid>
      <dc:creator>dharmendars007</dc:creator>
      <dc:date>2024-12-16T12:35:16Z</dc:date>
    </item>
    <item>
      <title>Re: Formula Battery With Previous Row and with MIN and MAX</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Formula-Battery-With-Previous-Row-and-with-MIN-and-MAX/m-p/4330886#M171915</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="796215" data-lia-user-login="dharmendars007" class="lia-mention lia-mention-user"&gt;dharmendars007&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;Thankyou for your answer!&lt;/P&gt;&lt;P&gt;But the formula gives an error:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2024 13:33:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Formula-Battery-With-Previous-Row-and-with-MIN-and-MAX/m-p/4330886#M171915</guid>
      <dc:creator>PBINL</dc:creator>
      <dc:date>2024-12-16T13:33:27Z</dc:date>
    </item>
    <item>
      <title>Re: Formula Battery With Previous Row and with MIN and MAX</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Formula-Battery-With-Previous-Row-and-with-MIN-and-MAX/m-p/4331867#M171975</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="445451" data-lia-user-login="PBINL" class="lia-mention lia-mention-user"&gt;PBINL&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much&amp;nbsp;dharmendars007&amp;nbsp;for your prompt reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your question, here is the method I provided:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;“Table”&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Create a measure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Solution = 
VAR CurrentIndex = MAX('Table'[index])
VAR PreviousState = 
    CALCULATE(
        MAX('Table'[Cumulative]),
        FILTER(
            'Table',
            'Table'[index] &amp;lt; CurrentIndex
        )
    )
VAR InValue = MAX('Table'[In])
VAR OutValue = MAX('Table'[Out])
VAR Difference = InValue - OutValue
VAR NewState = COALESCE(PreviousState, 0) + Difference
RETURN 
IF(
    NewState &amp;lt; 0, 
    0,
    IF(
        NewState &amp;gt; 100, 
        100,
        NewState
    )
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The final result is that if the new cumulative state is less than 0, 0 is returned; if it is greater than 100, 100 is returned; otherwise, the new cumulative state is returned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the result.&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;Regards,&lt;/P&gt;
&lt;P&gt;Nono Chen&lt;/P&gt;
&lt;P&gt;If this &lt;STRONG&gt;&lt;EM&gt;post&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;helps, then please consider&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Accept it as the solution&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2024 01:47:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Formula-Battery-With-Previous-Row-and-with-MIN-and-MAX/m-p/4331867#M171975</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-12-17T01:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: Formula Battery With Previous Row and with MIN and MAX</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Formula-Battery-With-Previous-Row-and-with-MIN-and-MAX/m-p/4332325#M171995</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;The formule looks good but from row 8 the cumulative isn't working anymore?&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have placed your formula next to my manual 'solution' column:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2024 06:57:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Formula-Battery-With-Previous-Row-and-with-MIN-and-MAX/m-p/4332325#M171995</guid>
      <dc:creator>PBINL</dc:creator>
      <dc:date>2024-12-17T06:57:47Z</dc:date>
    </item>
    <item>
      <title>Re: Formula Battery With Previous Row and with MIN and MAX</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Formula-Battery-With-Previous-Row-and-with-MIN-and-MAX/m-p/4332403#M171998</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="445451" data-lia-user-login="PBINL" class="lia-mention lia-mention-user"&gt;PBINL&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you tell me what results you expect?&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2024 07:16:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Formula-Battery-With-Previous-Row-and-with-MIN-and-MAX/m-p/4332403#M171998</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-12-17T07:16:50Z</dc:date>
    </item>
    <item>
      <title>Re: Formula Battery With Previous Row and with MIN and MAX</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Formula-Battery-With-Previous-Row-and-with-MIN-and-MAX/m-p/4332622#M172001</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The outcome of the column 'Solution Nono Chen' should be equal to the 'Solution' column, I made this column manual.&lt;BR /&gt;The outcome should be 0 if the battery becomes below zero, but the next row has to calculate from 0. Row 8 is 3 and row 9 is 7 so the battery at row 9 has 10 in it.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2024 08:44:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Formula-Battery-With-Previous-Row-and-with-MIN-and-MAX/m-p/4332622#M172001</guid>
      <dc:creator>PBINL</dc:creator>
      <dc:date>2024-12-17T08:44:07Z</dc:date>
    </item>
  </channel>
</rss>

