Forum Discussion
Row Number help in calculated column
- 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,
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,