Forum Discussion
Rank Based on measures with row context.
- 9 years ago
mim, ImkeF, Anonymous - interesting problem.
Anonymous
I agree with your logic in the last post, and for Excel 2013 I would write the measure like this:
= IF ( HASONEVALUE ( MyTable[ID] ), RANKX ( FILTER ( ALL ( MyTable[ID] ), [TOSTR FORECAST DATE] = CALCULATE ( [TOSTR FORECAST DATE], VALUES ( MyTable[ID] ) ) ), MyTable[ID], VALUES ( MyTable[ID] ) ) )- Added a HASONEVALUE check to allow evaluation only for single IDs
- Within FILTER, the measure for the currently iterated ID is [TOSTR FORECAST DATE], and this is compared with the measure from the original filter context CALCULATE ( [TOSTR FORECAST DATE], VALUES ( MyTable[ID] ) ).
Putting VALUES ( MyTable[ID] ) as a filter argument effectively undoes the context transition. - Ranking is just based on ordering of IDs, descending by default. Can be tweaked.
Sample workbook here in case useful.
Cheers,
Owen :)
- Anonymous9 years ago
Wait, are you trying to tell me you actually understand the 3rd argument to RANKX? NOBODY DOES!! :D
Totally based on Owen's really good thinking, *I* would probably do this slightly differently to avoid the 3rd param:Rank of ID among those with same TOSTR FORECAST DATE 2:=IF (
HASONEVALUE ( MyTable[ID] ),
RANKX (
FILTER (
ALL ( MyTable[ID] ),
[TOSTR FORECAST DATE] = CALCULATE ( [TOSTR FORECAST DATE], VALUES ( MyTable[ID] ) )
),
CALCULATE( VALUES( MyTable[ID] ) )
)
)
mim, ImkeF, Anonymous - interesting problem.
Anonymous
I agree with your logic in the last post, and for Excel 2013 I would write the measure like this:
=
IF (
HASONEVALUE ( MyTable[ID] ),
RANKX (
FILTER (
ALL ( MyTable[ID] ),
[TOSTR FORECAST DATE]
= CALCULATE ( [TOSTR FORECAST DATE], VALUES ( MyTable[ID] ) )
),
MyTable[ID],
VALUES ( MyTable[ID] )
)
)- Added a HASONEVALUE check to allow evaluation only for single IDs
- Within FILTER, the measure for the currently iterated ID is [TOSTR FORECAST DATE], and this is compared with the measure from the original filter context CALCULATE ( [TOSTR FORECAST DATE], VALUES ( MyTable[ID] ) ).
Putting VALUES ( MyTable[ID] ) as a filter argument effectively undoes the context transition. - Ranking is just based on ordering of IDs, descending by default. Can be tweaked.
Sample workbook here in case useful.
Cheers,
Owen :)
Wait, are you trying to tell me you actually understand the 3rd argument to RANKX? NOBODY DOES!! :D
Totally based on Owen's really good thinking, *I* would probably do this slightly differently to avoid the 3rd param:
Rank of ID among those with same TOSTR FORECAST DATE 2:=IF (
HASONEVALUE ( MyTable[ID] ),
RANKX (
FILTER (
ALL ( MyTable[ID] ),
[TOSTR FORECAST DATE] = CALCULATE ( [TOSTR FORECAST DATE], VALUES ( MyTable[ID] ) )
),
CALCULATE( VALUES( MyTable[ID] ) )
)
)