Forum Discussion
RANKX Formula duplicating ranks when value is the same
Hey team,
I have been trying for hours to get my RANKX formula to work but to no avail.
What I need is for my RANK measure to rank my group names by my YTD amount measure. I used the below formula to do this and it works EXCEPT when Groups have the same YTD amount i.e. 0. In this case, it just repeats the last known rank rather than continuing. Once the YTD amount hits 0 the rank needs to keep counting but it'll show the groups alphabetically with the continuing rank.
My formula :
Please help!
Hey everyone,
Thanks for the help but I've managed to find a solution by reading up on some articles, below was all I needed to do:
Rank =RANK (DENSE,ALLSELECTED ( 'bcs vw_pbi_sales_detail'[Group Name] ),ORDERBY ( [YTD Amount], DESC, 'bcs vw_pbi_sales_detail'[Group Name], ASC ))Thanks
5 Replies
- sophie-burgessRegular Visitor
Hey everyone,
Thanks for the help but I've managed to find a solution by reading up on some articles, below was all I needed to do:
Rank =RANK (DENSE,ALLSELECTED ( 'bcs vw_pbi_sales_detail'[Group Name] ),ORDERBY ( [YTD Amount], DESC, 'bcs vw_pbi_sales_detail'[Group Name], ASC ))Thanks - DanieleUgoCopp
Super User
Hello,
try with this formula, I think it should workRank =
RANKX(
ALLSELECTED('bcs vw_pbi_sales_detail'[Group Name]),
[YTD Amount] * 1000000
+ RANKX(
ALLSELECTED('bcs vw_pbi_sales_detail'[Group Name]),
'bcs vw_pbi_sales_detail'[Group Name],
,
ASC,
Dense
),
,
DESC,
Skip
)- sophie-burgessRegular Visitor
Hey Daniel,
I tried your formula and got the below erorr:
A single value for column 'Group Name' in table 'bcs vw_pbi_sales_detail' cannot be determined. This can happen when a measure or function formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.
My sales details table includes invoices as a column so there are multiple instances of Group Name.Cheers
- BeaBF
Super User
sophie-burgess Hi! Try:
Rank =
VAR CurrentYTD = [YTD Amount]
VAR CurrentGroup = SELECTEDVALUE('bcs vw_pbi_sales_detail'[Group Name])
RETURN
RANKX(
ALLSELECTED('bcs vw_pbi_sales_detail'[Group Name]),
[YTD Amount]
+
DIVIDE(
RANKX(
ALLSELECTED('bcs vw_pbi_sales_detail'[Group Name]),
SELECTEDVALUE('bcs vw_pbi_sales_detail'[Group Name]),
,
ASC
),
1000000
),
,
DESC,
Skip
)
BBF
💡 Did I answer your question? Mark my post as a solution!
👍 Kudos are appreciated
🔥 Proud to be a Super User!
- sophie-burgessRegular Visitor
Hey BeaBF,
I'm afraid this didn't change anything - I'm still seeing the duplicating rank numbers for group names where the YTS is 0 😞
Cheers