Forum Discussion
Anonymous
2 years agoNot applicable
Avoid Context When Ranking
Hi , I want to rank my table based only on the Name column, even if I bring in any number of columns into the context (like Column2, Column3). The measure I use now removes the context from Column1,...
- 2 years ago
Understood, thanks for clarifying Anonymous 🙂
If we call the relevant fact table FactTable, you could write something like this:
RANK = IF ( NOT ISEMPTY ( FactTable ), VAR Names = CALCULATETABLE ( SUMMARIZE ( FactTable, D_TEST[NAME] ), ALLSELECTED () ) RETURN RANK ( DENSE, Names ) )This should return a "dense" rank based solely on D_TEST[NAME]. The ranking is relative to the list of NAME values for which the FactTable is nonempty in the ALLSELECTED() context.
It will only return a rank when FactTable is nonempty.
Does this work for you?
OwenAuger
2 years agoSuper User
Hi Anonymous
Since you want to rank just by the NAME column, try either of these, assuming you want the rank to be in ascending order of D_TEST[NAME]:
RANK =
RANK ( DENSE, ALL ( D_TEST[NAME] ) )RANK =
RANK ( DENSE, ALLSELECTED ( D_TEST[NAME] ) )
For descending order, add an ORDERBY argument, e.g.
RANK =
RANK ( DENSE, ALL ( D_TEST[NAME] ), ORDERBY ( D_TEST[NAME], DESC) )
Do the above work for you?