Forum Discussion
sivasrao
3 years agoHelper III
Row Count value assigned to Previous Row
The below table has 2 columns, Event Target C 0 C 0 C 3 R 0 R 0 R 0 C 0 C 2 R 0 R 0 My requirement is Target Column. Target: The count of t...
Anonymous
3 years agoNot applicable
Hi sivasrao ,
Firstly, I think you need to add an index column in Power Query Editor.
Then you can create a calculated column by below code to achieve your goal.
Target =
VAR _Step1 =
ADDCOLUMNS (
'Table',
"Column1",
CALCULATE (
MIN ( 'Table'[Index] ),
FILTER (
'Table',
'Table'[Index] >= EARLIER ( 'Table'[Index] )
&& 'Table'[Event] = "R"
)
)
)
VAR _Step2 =
ADDCOLUMNS (
_Step1,
"Column2",
MAXX (
FILTER ( _Step1, [Event] <> "R" && [Index] <= EARLIER ( [Index] ) ),
[Column1]
)
)
VAR _Step3 =
ADDCOLUMNS (
_Step2,
"Column3",
VAR _MAXR =
MAXX ( FILTER ( _Step2, [Column2] = EARLIER ( [Column2] ) ), [Index] )
RETURN
IF ( [Index] = [Column1] - 1, _MAXR - [Column2] + 1, 0 )
)
RETURN
SUMX ( FILTER ( _Step3, [Index] = EARLIER ( 'Table'[Index] ) ), [Column3] )
Result is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
sivasrao
3 years agoHelper III
Thank you for the reply.
Perfect solution.👍
But a little bit confused about DAX. 🙂