Forum Discussion
most recent value of same calculated column previous row using Variable
- 3 years ago
surajde , Create a new column like
if([Time] =0, 0, countx(filter(Table, [ID] = earlier([ID]) && [Time] >0 && [Current Group Time] <= earlier([Current Group Time])), [ID]) )
- 3 years ago
Hi surajde ,
According to your description, here's my solution.
1.Add an index column in Power Query.
2.Create two calculated columns.
flag = IF ( 'Table'[ID] <> MAXX ( FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 ), 'Table'[ID] ), "yes", "no" )Column = VAR _c = 'Table'[Index] RETURN IF ( [ID] <> MAXX ( FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 ), 'Table'[ID] ), 0, IF ( MAXX ( FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 ), 'Table'[flag] ) = "no", IF ( 'Table'[Time] = 0, COUNTROWS ( FILTER ( 'Table', 'Table'[Index] < EARLIER ( 'Table'[Index] ) && 'Table'[Index] > MAXX ( FILTER ( 'Table', 'Table'[flag] = "yes" && 'Table'[Index] < _c ), 'Table'[Index] ) && 'Table'[Time] <> 0 ) ) + 0, COUNTROWS ( FILTER ( 'Table', 'Table'[Index] < EARLIER ( 'Table'[Index] ) && 'Table'[Index] > MAXX ( FILTER ( 'Table', 'Table'[flag] = "yes" && 'Table'[Index] < _c ), 'Table'[Index] ) && 'Table'[Time] <> 0 ) ) + 1 ), IF ( 'Table'[Time] = 0, 0, 1 ) ) )Get the correct result.
I also change the data source with different IDs, still get correct result.
I attach my file below for your reference.
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Best regards,
Community Support Team_yanjiang
Hi surajde ,
According to your description, here's my solution.
1.Add an index column in Power Query.
2.Create two calculated columns.
flag =
IF (
'Table'[ID]
<> MAXX (
FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 ),
'Table'[ID]
),
"yes",
"no"
)
Column =
VAR _c = 'Table'[Index]
RETURN
IF (
[ID]
<> MAXX (
FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 ),
'Table'[ID]
),
0,
IF (
MAXX (
FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 ),
'Table'[flag]
) = "no",
IF (
'Table'[Time] = 0,
COUNTROWS (
FILTER (
'Table',
'Table'[Index] < EARLIER ( 'Table'[Index] )
&& 'Table'[Index]
> MAXX (
FILTER ( 'Table', 'Table'[flag] = "yes" && 'Table'[Index] < _c ),
'Table'[Index]
)
&& 'Table'[Time] <> 0
)
) + 0,
COUNTROWS (
FILTER (
'Table',
'Table'[Index] < EARLIER ( 'Table'[Index] )
&& 'Table'[Index]
> MAXX (
FILTER ( 'Table', 'Table'[flag] = "yes" && 'Table'[Index] < _c ),
'Table'[Index]
)
&& 'Table'[Time] <> 0
)
) + 1
),
IF ( 'Table'[Time] = 0, 0, 1 )
)
)
Get the correct result.
I also change the data source with different IDs, still get correct result.
I attach my file below for your reference.
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Best regards,
Community Support Team_yanjiang
Amazing!! This one worked 😀