Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

Row Number help in calculated column

Hi,   Wanted to have calcualted column based on the Value column >0 based on Date and Partial attributes and it should repeate every month for different partial as mentioned below.   any help ...
  • DataNinja777's avatar
    1 year ago

    Hi Anonymous ,

     

    To calculate a running row number in a calculated column based on Value > 0, grouped by Partial and maintaining the row sequence across time, you can use DAX like this:

    Row starts =
    VAR CurrentDate = [Dt]
    VAR CurrentPartial = [Partial]
    VAR CurrentIndex = [Index]
    RETURN
    IF (
        [Value] > 0,
        CALCULATE (
            COUNTROWS (
                FILTER (
                    YourTable,
                    [Partial] = CurrentPartial &&
                    [Dt] <= CurrentDate &&
                    [Value] > 0 &&
                    [Index] <= CurrentIndex
                )
            )
        ),
        0
    )
    

    This assumes you already have a unique [Index] column that ensures each row has a deterministic order. The logic checks if the current row has Value > 0. If so, it counts all prior rows with the same Partial, date up to the current one, and with Value > 0. This count becomes the row number. If Value is zero, it returns 0. The row number continues to increment for each non-zero value across time, separately for each Partial.

     

    Best regards,