<?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 reset in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-reset/m-p/4344650#M172522</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="905626" data-lia-user-login="matus_jun" class="lia-mention lia-mention-user"&gt;matus_jun&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To calculate the running count of NewDayType based on your condition, where the count continues if NewDayType is 1 and resets to 0 if NewDayType is 0, while grouping by employee-id, you can create a calculated column in Power BI using DAX.&lt;/P&gt;
&lt;P&gt;The DAX formula for the calculated column is as follows:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;RunningCount = 
VAR CurrentIndex = 'Table'[Index]
VAR CurrentEmployee = 'Table'[employee-id]
VAR FilteredTable = 
    FILTER(
        'Table',
        'Table'[employee-id] = CurrentEmployee &amp;amp;&amp;amp;
        'Table'[Index] &amp;lt;= CurrentIndex
    )
RETURN
    IF(
        'Table'[NewDayType] = 0,
        0,
        COUNTROWS(
            FILTER(
                FilteredTable,
                'Table'[NewDayType] = 1
            )
        )
    )
&lt;/LI-CODE&gt;
&lt;P&gt;This formula works by first identifying the current row’s Index and employee-id to ensure the calculation is scoped correctly for each employee. It then filters the table to include only rows belonging to the current employee and with an Index less than or equal to the current row. If the NewDayType is 0 for the current row, the result is set to 0. Otherwise, it calculates the count of rows in the filtered table where NewDayType is 1.&lt;/P&gt;
&lt;P&gt;When applied, this will generate a column that resets to 0 whenever NewDayType is 0 and continues counting for NewDayType = 1 within the same employee-id. This ensures the running count logic respects the reset condition and the grouping by employee.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;</description>
    <pubDate>Fri, 27 Dec 2024 13:15:41 GMT</pubDate>
    <dc:creator>DataNinja777</dc:creator>
    <dc:date>2024-12-27T13:15:41Z</dc:date>
    <item>
      <title>Count reset</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-reset/m-p/4344402#M172512</link>
      <description>&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Im sorry my english is not good&amp;nbsp;&lt;BR /&gt;what i want is count NewdayType if&amp;nbsp;NewdayType is 1 continue counting if 0 set to 0&amp;nbsp;&lt;BR /&gt;base on emp_id&lt;/P&gt;</description>
      <pubDate>Fri, 27 Dec 2024 08:38:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-reset/m-p/4344402#M172512</guid>
      <dc:creator>matus_jun</dc:creator>
      <dc:date>2024-12-27T08:38:31Z</dc:date>
    </item>
    <item>
      <title>Re: Count reset</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-reset/m-p/4344650#M172522</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="905626" data-lia-user-login="matus_jun" class="lia-mention lia-mention-user"&gt;matus_jun&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To calculate the running count of NewDayType based on your condition, where the count continues if NewDayType is 1 and resets to 0 if NewDayType is 0, while grouping by employee-id, you can create a calculated column in Power BI using DAX.&lt;/P&gt;
&lt;P&gt;The DAX formula for the calculated column is as follows:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;RunningCount = 
VAR CurrentIndex = 'Table'[Index]
VAR CurrentEmployee = 'Table'[employee-id]
VAR FilteredTable = 
    FILTER(
        'Table',
        'Table'[employee-id] = CurrentEmployee &amp;amp;&amp;amp;
        'Table'[Index] &amp;lt;= CurrentIndex
    )
RETURN
    IF(
        'Table'[NewDayType] = 0,
        0,
        COUNTROWS(
            FILTER(
                FilteredTable,
                'Table'[NewDayType] = 1
            )
        )
    )
&lt;/LI-CODE&gt;
&lt;P&gt;This formula works by first identifying the current row’s Index and employee-id to ensure the calculation is scoped correctly for each employee. It then filters the table to include only rows belonging to the current employee and with an Index less than or equal to the current row. If the NewDayType is 0 for the current row, the result is set to 0. Otherwise, it calculates the count of rows in the filtered table where NewDayType is 1.&lt;/P&gt;
&lt;P&gt;When applied, this will generate a column that resets to 0 whenever NewDayType is 0 and continues counting for NewDayType = 1 within the same employee-id. This ensures the running count logic respects the reset condition and the grouping by employee.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;</description>
      <pubDate>Fri, 27 Dec 2024 13:15:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-reset/m-p/4344650#M172522</guid>
      <dc:creator>DataNinja777</dc:creator>
      <dc:date>2024-12-27T13:15:41Z</dc:date>
    </item>
    <item>
      <title>Re: Count reset</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-reset/m-p/4345697#M172577</link>
      <description>&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;running count is not reset when newdaytype is 0&amp;nbsp; it should be 1,2,3,4,5,0,1,2,3,4,5,6 something like this&lt;BR /&gt;&amp;nbsp;Thank you alot for you help&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2024 02:09:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-reset/m-p/4345697#M172577</guid>
      <dc:creator>matus_jun</dc:creator>
      <dc:date>2024-12-30T02:09:14Z</dc:date>
    </item>
    <item>
      <title>Re: Count reset</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-reset/m-p/4345715#M172578</link>
      <description>&lt;P&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="905626" data-lia-user-login="matus_jun" class="lia-mention lia-mention-user"&gt;matus_jun&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Based on the testing, try using the following DAX formula to create a new column.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;CountByNewDayType = 
VAR CurrentEmployee = 'New day table'[employee_id]
VAR CurrentIndex = 'New day table'[Index]
VAR PreviousRows =
    FILTER(
        'New day table',
        'New day table'[employee_id] = CurrentEmployee &amp;amp;&amp;amp;
        'New day table'[Index] &amp;lt; CurrentIndex
    )
VAR PrevRowWithZero =
    MAXX(
        FILTER(
            PreviousRows,
            'New day table'[NewDayType] = 0
        ),
        'New day table'[Index]
    )
RETURN
IF(
    'New day table'[NewDayType] = 0,
    0,
    COUNTROWS(
        FILTER(
            PreviousRows,
            'New day table'[Index] &amp;gt; PrevRowWithZero
        )
    ) + 1
)&lt;/LI-CODE&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Wisdom Wu&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If this post&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;helps&lt;/EM&gt;&lt;/STRONG&gt;, 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;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2024 02:36:02 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-reset/m-p/4345715#M172578</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-12-30T02:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: Count reset</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-reset/m-p/4345723#M172579</link>
      <description>&lt;P&gt;wow It work thank you alot&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2024 02:46:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-reset/m-p/4345723#M172579</guid>
      <dc:creator>matus_jun</dc:creator>
      <dc:date>2024-12-30T02:46:11Z</dc:date>
    </item>
  </channel>
</rss>

