Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I am struggling to figure out how to use the RANKX function. I've made my DAX work using
Solved! Go to Solution.
Hi Rodger,
The ALLSELECTED makes sure that you only consider the "selected" Invoice[Product Names] when the rank is calculated. When you use ALL, as you can guess, the total sales for all product names are considered and you may end up gaps in your ranking sequence. So normally this does not explain why you get 1's when using ALL, so that could be related to your data model and definition of [Total Sales].
But typically you get all 1's from RankX when you use the measure in the wrong context. For instance if you use you measure in a matrix with rows per country, you will get 1's.
The reasons is that the lookup table used for [total sales] contains the total sales amounts by country and by product and the lookup table used to determine the rank only contains values per country. Therefore the total per country (used for ranking) is always higher (or equal at best when there is just one product in the country) than any the total per product within a given country.
I also see that you use the parameter 'desc', which is not necessary because it is the default setting, and you wrap the [Total Sales] measure with CALCULATE which is not necessary since a measure already contains an implicit CALCULATE. So RANKX(ALLSELECTED(Invoices[Product Name]),[Total Sales]) should give the same result.
Hope this helps.
jan
Hi Rodger,
The ALLSELECTED makes sure that you only consider the "selected" Invoice[Product Names] when the rank is calculated. When you use ALL, as you can guess, the total sales for all product names are considered and you may end up gaps in your ranking sequence. So normally this does not explain why you get 1's when using ALL, so that could be related to your data model and definition of [Total Sales].
But typically you get all 1's from RankX when you use the measure in the wrong context. For instance if you use you measure in a matrix with rows per country, you will get 1's.
The reasons is that the lookup table used for [total sales] contains the total sales amounts by country and by product and the lookup table used to determine the rank only contains values per country. Therefore the total per country (used for ranking) is always higher (or equal at best when there is just one product in the country) than any the total per product within a given country.
I also see that you use the parameter 'desc', which is not necessary because it is the default setting, and you wrap the [Total Sales] measure with CALCULATE which is not necessary since a measure already contains an implicit CALCULATE. So RANKX(ALLSELECTED(Invoices[Product Name]),[Total Sales]) should give the same result.
Hope this helps.
jan
please check below link for better understanding.
Thanks & regards,
Pravin Wattamwar
if it resolves your problem Give kudos and mark it as solution
User | Count |
---|---|
25 | |
12 | |
8 | |
6 | |
6 |
User | Count |
---|---|
26 | |
12 | |
11 | |
8 | |
7 |