Forum Discussion
rank() function not working as expected (NOT USING RANKX)
- 8 months ago
Thanks for sharing the pbix as that makes it much easier to troubleshoot.
The reason that the measure is not working in your pbix is because of the [Rank_TopN Reward Value] is not blank filter on the visual. This adds a value filter to the visual's SUMMARIZECOLUMNS, which does not interact well with the ADDCOLUMNS I had originally used. We can circumvent this issue if we use SUMMARIZECOLUMNS instead. This worked for me with the is not blank filter in your shared pbix.
Rank_TopN Reward Value fixed = VAR _topN = SELECTEDVALUE('TopN'[Top N]) VAR _core = SUMMARIZECOLUMNS( v_flt_ci_cs_adjustment_rwd[Loyalty ID], ALLSELECTED( v_flt_ci_cs_adjustment_rwd[Loyalty ID], v_flt_ci_cs_adjustment_rwd[reward_issue_date] ), "@selectedSum", CALCULATE( SUM( v_flt_ci_cs_adjustment_rwd[sum_reward_value] ) ) ) VAR _rank = RANK( DENSE, _core, ORDERBY( [@selectedSum], DESC ) ) RETURN IF( _rank > 0 && _rank <= _topN, _rank )
Thanks for sharing the pbix as that makes it much easier to troubleshoot.
The reason that the measure is not working in your pbix is because of the [Rank_TopN Reward Value] is not blank filter on the visual. This adds a value filter to the visual's SUMMARIZECOLUMNS, which does not interact well with the ADDCOLUMNS I had originally used. We can circumvent this issue if we use SUMMARIZECOLUMNS instead. This worked for me with the is not blank filter in your shared pbix.
Rank_TopN Reward Value fixed =
VAR _topN = SELECTEDVALUE('TopN'[Top N])
VAR _core =
SUMMARIZECOLUMNS(
v_flt_ci_cs_adjustment_rwd[Loyalty ID],
ALLSELECTED(
v_flt_ci_cs_adjustment_rwd[Loyalty ID],
v_flt_ci_cs_adjustment_rwd[reward_issue_date]
),
"@selectedSum", CALCULATE( SUM( v_flt_ci_cs_adjustment_rwd[sum_reward_value] ) )
)
VAR _rank = RANK( DENSE, _core, ORDERBY( [@selectedSum], DESC ) )
RETURN
IF( _rank > 0 && _rank <= _topN, _rank )
MarkLaf I CANNOT thank you enough for all the effort in helping me. I noticed that your original formula works if I leaves the "rank is not blank" filter out (except that, of course, it also shows blanks). And I see that the new formula works WITH the "rank is not blank" filter included.
I will look up summarize columns and add columns, but if you have any advice on how I can wrap my head around this more clearly, please advise. THANK YOU AGAIN!!!!!! 👏👏