<?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: Increment value with condition in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Increment-value-with-condition/m-p/3710109#M144353</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="685737" data-lia-user-login="jc173" class="lia-mention lia-mention-user"&gt;jc173&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Based on your questions, here are my answers.&lt;/P&gt;
&lt;P&gt;Firstly, create a table as you mentioned.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Then go to the &lt;STRONG&gt;Power Query&lt;/STRONG&gt; and select the &lt;STRONG&gt;Index Column&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Enter the appropriate DAX code to get the results you need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Column = 
IF (
    'Table'[Column1] &amp;lt;&amp;gt; 0,
    RANKX ( FILTER ( 'Table', 'Table'[Column1] = 0 ), 'Table'[Index],,ASC ),
    0
)&lt;/LI-CODE&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;
&lt;P style="margin-bottom: 6.0pt;"&gt;&lt;SPAN&gt;Best Regards&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin-bottom: 6.0pt;"&gt;&lt;SPAN&gt;Yilong Zhou&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin-bottom: 6.0pt;"&gt;&lt;SPAN&gt;If this post&amp;nbsp;&lt;STRONG&gt;&lt;I&gt;helps&lt;/I&gt;&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;STRONG&gt;&lt;I&gt;Accept it as the solution&lt;/I&gt;&lt;/STRONG&gt;&amp;nbsp;to help the other members find it more quickly.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 20 Feb 2024 07:25:26 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2024-02-20T07:25:26Z</dc:date>
    <item>
      <title>Increment value with condition</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Increment-value-with-condition/m-p/3707875#M144236</link>
      <description>&lt;P&gt;Hi guys i have this situation:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I would like to get this,&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Every time i have a 0 value i need to increment the value that i sum at the column.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2024 11:29:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Increment-value-with-condition/m-p/3707875#M144236</guid>
      <dc:creator>jc173</dc:creator>
      <dc:date>2024-02-19T11:29:10Z</dc:date>
    </item>
    <item>
      <title>Re: Increment value with condition</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Increment-value-with-condition/m-p/3708116#M144254</link>
      <description>&lt;P&gt;To achieve the desired result in Power BI using DAX, you can create a calculated column to track the cumulative sum based on the condition of encountering a 0 value. Here's how you can do it:&lt;/P&gt;&lt;P&gt;Assuming your table is named "Table1" and the column containing the original values is named "Value", you can follow these steps:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;Create a new calculated column by clicking on "Modeling" in the top menu, then selecting "New Column".&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Use the following DAX expression to create the calculated column:&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;CumulativeSum =&lt;BR /&gt;VAR CurrentValue = Table1[Value]&lt;BR /&gt;VAR CumulativeSum =&lt;BR /&gt;CALCULATE(&lt;BR /&gt;SUM(Table1[Value]),&lt;BR /&gt;FILTER(&lt;BR /&gt;ALL(Table1),&lt;BR /&gt;Table1[Value] &amp;lt;&amp;gt; 0 &amp;amp;&amp;amp;&lt;BR /&gt;Table1[Value] &amp;lt;= CurrentValue&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;RETURN&lt;BR /&gt;IF(Table1[Value] = 0, 0, CumulativeSum)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Explanation:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The VAR CurrentValue stores the current value of the row.&lt;/LI&gt;&lt;LI&gt;The VAR CumulativeSum calculates the cumulative sum of values that meet the conditions: not equal to 0 and less than or equal to the current value.&lt;/LI&gt;&lt;LI&gt;The IF function checks if the current value is 0. If it is, it returns 0; otherwise, it returns the CumulativeSum.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;After creating this calculated column, you should see the desired result where the cumulative sum increments only when encountering a 0 value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;If this post&amp;nbsp;helps, then please consider&amp;nbsp;Accepting it as the solution&amp;nbsp;to help the other members find it more quickly.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;In case there is still a problem, please feel free and explain your issue in detail,&amp;nbsp;It will be my pleasure to assist you in any way I can.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2024 13:26:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Increment-value-with-condition/m-p/3708116#M144254</guid>
      <dc:creator>123abc</dc:creator>
      <dc:date>2024-02-19T13:26:43Z</dc:date>
    </item>
    <item>
      <title>Re: Increment value with condition</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Increment-value-with-condition/m-p/3708222#M144265</link>
      <description>&lt;P&gt;Hi thanks for the replie, but i'am on power bi online (Data FActory) and i don't have the possibility to insert a calculated column&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2024 14:09:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Increment-value-with-condition/m-p/3708222#M144265</guid>
      <dc:creator>jc173</dc:creator>
      <dc:date>2024-02-19T14:09:54Z</dc:date>
    </item>
    <item>
      <title>Re: Increment value with condition</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Increment-value-with-condition/m-p/3709832#M144339</link>
      <description>&lt;P&gt;If you're working in Power BI online or using Data Factory where you can't create calculated columns directly, you can achieve the desired outcome using DAX measures. Here's how you can do it:&lt;/P&gt;&lt;P&gt;Assuming you have a table named "YourTable" with a column named "Value" that contains your values, you can create a measure using DAX to compute the incremented values based on your condition.&lt;/P&gt;&lt;P&gt;Here's the DAX measure you can use:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Incremented Value =&lt;BR /&gt;VAR MaxRowIndex = MAX('YourTable'[Index])&lt;BR /&gt;VAR PrevIncrement =&lt;BR /&gt;CALCULATE(&lt;BR /&gt;MAX('YourTable'[Incremented Value]),&lt;BR /&gt;FILTER(&lt;BR /&gt;ALL('YourTable'),&lt;BR /&gt;'YourTable'[Index] &amp;lt; MaxRowIndex &amp;amp;&amp;amp;&lt;BR /&gt;'YourTable'[Value] = 0&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;RETURN&lt;BR /&gt;IF('YourTable'[Value] = 0, PrevIncrement + 1, PrevIncrement)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Make sure to replace 'YourTable', 'Index', 'Value', and 'Incremented Value' with the actual names of your table and columns.&lt;/P&gt;&lt;P&gt;This measure works as follows:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;It finds the maximum index value for the current row.&lt;/LI&gt;&lt;LI&gt;It calculates the previous increment value based on the condition that the index is less than the current row's index and the value is 0.&lt;/LI&gt;&lt;LI&gt;If the value for the current row is 0, it increments the previous increment value by 1; otherwise, it returns the previous increment value.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;You can then use this measure in your visuals to display the incremented values based on your condition.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;If this post&amp;nbsp;helps, then please consider&amp;nbsp;Accepting it as the solution&amp;nbsp;to help the other members find it more quickly.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;In case there is still a problem, please feel free and explain your issue in detail,&amp;nbsp;It will be my pleasure to assist you in any way I can.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2024 05:30:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Increment-value-with-condition/m-p/3709832#M144339</guid>
      <dc:creator>123abc</dc:creator>
      <dc:date>2024-02-20T05:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: Increment value with condition</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Increment-value-with-condition/m-p/3710109#M144353</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="685737" data-lia-user-login="jc173" class="lia-mention lia-mention-user"&gt;jc173&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Based on your questions, here are my answers.&lt;/P&gt;
&lt;P&gt;Firstly, create a table as you mentioned.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Then go to the &lt;STRONG&gt;Power Query&lt;/STRONG&gt; and select the &lt;STRONG&gt;Index Column&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Enter the appropriate DAX code to get the results you need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Column = 
IF (
    'Table'[Column1] &amp;lt;&amp;gt; 0,
    RANKX ( FILTER ( 'Table', 'Table'[Column1] = 0 ), 'Table'[Index],,ASC ),
    0
)&lt;/LI-CODE&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;
&lt;P style="margin-bottom: 6.0pt;"&gt;&lt;SPAN&gt;Best Regards&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin-bottom: 6.0pt;"&gt;&lt;SPAN&gt;Yilong Zhou&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin-bottom: 6.0pt;"&gt;&lt;SPAN&gt;If this post&amp;nbsp;&lt;STRONG&gt;&lt;I&gt;helps&lt;/I&gt;&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;STRONG&gt;&lt;I&gt;Accept it as the solution&lt;/I&gt;&lt;/STRONG&gt;&amp;nbsp;to help the other members find it more quickly.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2024 07:25:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Increment-value-with-condition/m-p/3710109#M144353</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-02-20T07:25:26Z</dc:date>
    </item>
  </channel>
</rss>

