<?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: Count Rows Based On Previous Row's value. in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Rows-Based-On-Previous-Row-s-value/m-p/2706644#M82087</link>
    <description>&lt;P&gt;Thank you for your solution! I tested your suggestion by creating a smaller spreadsheet with only 50 items and manually counted how many "zeros" were followed in the next row by numbers greater than "zero". When I applied your measure/index idea, it came out to the right number!! I modified your code slightly to use "&amp;gt; 0" instead of "+ 1" in this part of the code (see example below) to count all "zeros" followed by any number greater than "zero":&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;INT(__CURRENTDIGIT=0 &amp;amp;&amp;amp; __NEXTDIGIST = 1)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 17 Aug 2022 12:59:08 GMT</pubDate>
    <dc:creator>MrFahrenheit</dc:creator>
    <dc:date>2022-08-17T12:59:08Z</dc:date>
    <item>
      <title>Count Rows Based On Previous Row's value.</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Rows-Based-On-Previous-Row-s-value/m-p/2704133#M81958</link>
      <description>&lt;P&gt;I have one column and it has 0s and 1s in it. I ONLY want to count the 0s which are followed by a 1 in the next row. For example, 0,1,0,1,0,1 would count 3 x 0s. Another example, 0,0,0,0,1 would only count one 0 because only one 0 is followed by a 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;0&lt;/P&gt;&lt;P&gt;0&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;= 1 x 0 (only one 0 is followed by a 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;0&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;0&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;0&lt;/P&gt;&lt;P&gt;0&lt;/P&gt;&lt;P&gt;= 2 x 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If anyone knows how to do this, please let me know. I checked into all the "Count" expressions but couldn't figure it out.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2022 18:20:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Rows-Based-On-Previous-Row-s-value/m-p/2704133#M81958</guid>
      <dc:creator>MrFahrenheit</dc:creator>
      <dc:date>2022-08-16T18:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Count Rows Based On Previous Row's value.</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Rows-Based-On-Previous-Row-s-value/m-p/2704175#M81963</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="95633" data-lia-user-login="MrFahrenheit" class="lia-mention lia-mention-user"&gt;MrFahrenheit&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;First, add an index column to your table in Power Query:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Then create the following measure to calculate the count:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Zero Count = 
    SUMX(
        Table4,
        VAR __CURRENTINDEX = Table4[Index]
        VAR __NEXTINDEX = __CURRENTINDEX + 1
        VAR __CURRENTDIGIT = Table4[Digit]        
        VAR __NEXTDIGIST = CALCULATE( MAX(Table4[Digit]) , Table4[Index] = __NEXTINDEX , REMOVEFILTERS(Table4))
        RETURN
        INT(__CURRENTDIGIT=0 &amp;amp;&amp;amp; __NEXTDIGIST = 1)
    )&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&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>Tue, 16 Aug 2022 18:54:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Rows-Based-On-Previous-Row-s-value/m-p/2704175#M81963</guid>
      <dc:creator>Fowmy</dc:creator>
      <dc:date>2022-08-16T18:54:42Z</dc:date>
    </item>
    <item>
      <title>Re: Count Rows Based On Previous Row's value.</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Rows-Based-On-Previous-Row-s-value/m-p/2706644#M82087</link>
      <description>&lt;P&gt;Thank you for your solution! I tested your suggestion by creating a smaller spreadsheet with only 50 items and manually counted how many "zeros" were followed in the next row by numbers greater than "zero". When I applied your measure/index idea, it came out to the right number!! I modified your code slightly to use "&amp;gt; 0" instead of "+ 1" in this part of the code (see example below) to count all "zeros" followed by any number greater than "zero":&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;INT(__CURRENTDIGIT=0 &amp;amp;&amp;amp; __NEXTDIGIST = 1)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2022 12:59:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Rows-Based-On-Previous-Row-s-value/m-p/2706644#M82087</guid>
      <dc:creator>MrFahrenheit</dc:creator>
      <dc:date>2022-08-17T12:59:08Z</dc:date>
    </item>
  </channel>
</rss>

