Greg_Deckler
7 years agoCommunity Champion
Cthulhu
Why Cthulhu? Because the mental gymnastics required to figure this out nearly drove me insane. And because the exact reason you would need this measure is probably beyond the comprehension of mere mo...
AlexisOlson
2 years agoSuper User
Greg_Deckler, here's an approach using the newer WINDOW functions.
Local Group Index =
VAR _GlobalGroup_ = /* All rows with current animal up to current row */
WINDOW (
1, ABS, /* From frirst row */
0, REL, /* Up to current row */
ORDERBY ( Cthulhu[Index] ),
PARTITIONBY ( Cthulhu[Animal] )
)
VAR _AddPrevIndex_ = /* Lookup previous index for each row */
ADDCOLUMNS (
_GlobalGroup_,
"@PrevIndex",
VAR _PrevRow_ =
OFFSET ( -1, _GlobalGroup_, ORDERBY ( Cthulhu[Index] ) )
VAR _PrevIndex =
MAXX ( _PrevRow_, Cthulhu[Index] )
RETURN
_PrevIndex
)
VAR _Skips_ = /* All rows where prev index isn't current index - 1 */
FILTER ( _AddPrevIndex_, [@PrevIndex] < Cthulhu[Index] - 1 )
/* Will be empty if there are no such skips */
VAR _LocalGroupStart = /* Latest skip -- blank if _Skips_ is empty */
MAXX ( _Skips_, Cthulhu[Index] )
VAR _LocalGroup_ = /* All rows since latest skip */
FILTER ( _AddPrevIndex_, Cthulhu[Index] >= _LocalGroupStart )
VAR _Rank = /* Current row is the last in the local group */
COUNTROWS ( _LocalGroup_ )
RETURN
_Rank