Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
matus_jun
Frequent Visitor

Count reset

matus_jun_0-1735288601393.png

Im sorry my english is not good 
what i want is count NewdayType if NewdayType is 1 continue counting if 0 set to 0 
base on emp_id

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @matus_jun ,

Based on the testing, try using the following DAX formula to create a new column.

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 &&
        'New day table'[Index] < 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] > PrevRowWithZero
        )
    ) + 1
)

vjiewumsft_0-1735526041474.png

Best Regards,

Wisdom Wu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @matus_jun ,

Based on the testing, try using the following DAX formula to create a new column.

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 &&
        'New day table'[Index] < 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] > PrevRowWithZero
        )
    ) + 1
)

vjiewumsft_0-1735526041474.png

Best Regards,

Wisdom Wu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

wow It work thank you alot

DataNinja777
Super User
Super User

Hi @matus_jun ,

 

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.

The DAX formula for the calculated column is as follows:

RunningCount = 
VAR CurrentIndex = 'Table'[Index]
VAR CurrentEmployee = 'Table'[employee-id]
VAR FilteredTable = 
    FILTER(
        'Table',
        'Table'[employee-id] = CurrentEmployee &&
        'Table'[Index] <= CurrentIndex
    )
RETURN
    IF(
        'Table'[NewDayType] = 0,
        0,
        COUNTROWS(
            FILTER(
                FilteredTable,
                'Table'[NewDayType] = 1
            )
        )
    )

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.

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.

 

Best regards,

matus_jun_0-1735524367346.png

running count is not reset when newdaytype is 0  it should be 1,2,3,4,5,0,1,2,3,4,5,6 something like this
 Thank you alot for you help

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.