Forum Discussion
RANKX Function to Rank Table by Revenue
I am having trouble getting my rankx function to work. I have visited so many threads with similar questions but still can't seem to figure it out.
I have a table with product skus, item IDs, revenue amounts, etc. and want to rank them based on the revenue amount (item with the highest revenue will have a ranking of 1).
Here is my code, but I have tried so many variations of this (without sum, without calculate, without both, without DESC, without [sku], etc.)
Rank = rankx(ALL('PH FY 2016'[sku]),CALCULATE(SUM('PH FY 2016'[Net Revenue])),,DESC)The table won't load with this current code, and the closest I've gotten has returned all 1s. Any help is much appreciated!
I got it working with this code:
Rank = rankx(ALLSELECTED('PH FY 2016'[sku]),CALCULATE(SUM('PH FY 2016'[Net Revenue]), ALLEXCEPT('PH FY 2016','PH FY 2016'[sku], 'Cat DICT'[Category])))
4 Replies
- Vvelarde
Community Champion
If you are using a calculated Column:
Try with:
Ranking = RANKX(Table1;table1[Net Revenue];;DESC)
Regards
Victor
Lima - Peru
- khappersett
Resolver I
I am getting this error: A single value for column 'Net Revenue' in table 'PH FY 2016' cannot be determined.
I used this code...
Rank = rankx('PH FY 2016','PH FY 2016'[Net Revenue],,DESC)The Net Revenue column is not calculated - it was on the Excel table that I imported into Power BI.
- khappersett
Resolver I
I got it working with this code:
Rank = rankx(ALLSELECTED('PH FY 2016'[sku]),CALCULATE(SUM('PH FY 2016'[Net Revenue]), ALLEXCEPT('PH FY 2016','PH FY 2016'[sku], 'Cat DICT'[Category])))