Forum Discussion
Ranking measure with Table variable
Hello Folks,
I'm trying to create measure for Top 10 customers based on sales amount in Power BI which is connected Live to the Tabular model.
Customer is Dimension and Sales amount is in fact table and I need to Rank the customers from 1 to 10 based on highest sales amount for each customer.
I have tried to create this DAX query below but this gives me Rank '1' for all the rows, I am guessing this has to do with filter context.
Hi sqlguru448 ,
Be aware that making a summarizaition of a full table will bring for sure performance issues, in your case you are using the FACT table that I assume have a huge number of data so be aware of that.
Try the following code:
Measure = var temp_table = FILTER ( SUMMARIZE ( ALLSELECTED ( Customer[Name] ); Customer[Name]; "Total_Sales"; [Sales Amount] ); [Sales Amount] > 0 ) var Ranking = RANKX(temp_table; [Sales Amount]) RETURN RankingThen filter out all rankings above 10.
11 Replies
- vivran22Community Champion
Hello sqlguru448 ,
What is the expected result? Can you share a sample data/pbix file along with the expected results?
Cheers!
Vivek
Blog: vivran.in/my-blog
Connect on LinkedIn
Follow on Twitter- sqlguru448Helper III
Hi vivran22
Below is the sample data screenshot. The ranking should be from 1 to 10 based on highest sales amount. but my above dax gives me Rank 1 in all rows.
- Ashish_MathurSuper User
Hi,
Try this measure
=rankx(all(data[Customer]),[Sales])
I have assumed that sales is an explicit measure.
Hope this helps.