Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi guys,
I'm new in Power BI and DAX. I face any issue using RANKX DAX function. Could you please have a look and give me advice?
There 2 tables as below
What I'm trying to do is add 2 columns InsurerRank and InsurerGroupRank based on Total Net Earnings
I created a measure:
Total Net Earnings = SUM(Net Earnings)
I also added 2 columns into Insurers table:
InsurerRank = RANKX(ALL(Insurers), [Total Net Earnings])
InsurerGroupRank = RANKX(ALL(Insurers[Insurer Group]),[Total Net Earnings],, DESC)
But the result was not correct
Solved! Go to Solution.
HI @xuantalks,
You can try to use following calculate column to replace group with other based on their ranking.
Top 5 Group = VAR summary = SUMMARIZE ( ADDCOLUMNS ( Policy_Transactions, "Group", RELATED ( Insurers[Insurer_Group] ) ), [Group], "Total", SUM ( Policy_Transactions[Net_Earnings] ) ) VAR _rank = COUNTROWS ( FILTER ( summary, [Total] > MAXX ( FILTER ( summary, [Group] = EARLIER ( Insurers[Insurer_Group] ) ), [Total] ) ) ) + 1 RETURN IF ( _rank > 5, "Other", [Insurer_Group] )
Regards,
Xiaoxin Sheng
Hi @xuantalks,
If you mean you want to show dynamic rank based on current filter, I'd like to suggest you use allselected to replace all function and add additional parameter 'dense' to your formula.
InsurerRank = RANKX ( ALLSELECTED ( Insurers ), [Total Net Earnings],, DESC, DENSE ) InsurerGroupRank = RANKX ( ALLSELECTED ( Insurers[Insurer Group] ), [Total Net Earnings], , DESC, DENSE )
Regards,
Xiaoxin Sheng
Hi @xuantalks,
Can you please share a pbix file with some sample data for test?
Regards,
Xiaoxin Sheng
HI @xuantalks,
You can try to use following calculate column to replace group with other based on their ranking.
Top 5 Group = VAR summary = SUMMARIZE ( ADDCOLUMNS ( Policy_Transactions, "Group", RELATED ( Insurers[Insurer_Group] ) ), [Group], "Total", SUM ( Policy_Transactions[Net_Earnings] ) ) VAR _rank = COUNTROWS ( FILTER ( summary, [Total] > MAXX ( FILTER ( summary, [Group] = EARLIER ( Insurers[Insurer_Group] ) ), [Total] ) ) ) + 1 RETURN IF ( _rank > 5, "Other", [Insurer_Group] )
Regards,
Xiaoxin Sheng
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
94 | |
76 | |
62 | |
55 |
User | Count |
---|---|
142 | |
107 | |
89 | |
84 | |
65 |