Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
kjsullivan
Frequent Visitor

Top N with multiple variables

I am trying to make a 100% stacked bar chart that gives me the percentage of revenue shared by the top 2 industries in a state. I don't want the overall top 2 by all states. For example, Georgia could have industry x and y as there top 2 while Florida could have industry x and z. I saw that you could make a RANKX off of another post, but PowerBi kept giving me errors. The code is as follows: RANKX(ALL(Sheet1[Industry]),CALCULATE(SUM(Sheet1[Revenue]),ALLEXCEPT(Sheet1,Sheet1[Industry],Sheet1[State])),DESC,Dense). Does anyone know if there is a more efficient way or if my code is just wrong? Thanks.

1 ACCEPTED SOLUTION
v-caliao-msft
Microsoft Employee
Microsoft Employee

@kjsullivan,

 

Sample data and sample DAX expression for you reference.
Column = RANKX(FILTER(Table2,Table2[Country]=EARLIER(Table2[Country])),Table2[Amount],,DESC)
Capture.PNG

 

If this is not what you want, please provide us some sample data and your expected result, so that we can make further analysis.

 

Regards,

Charlie Liao

View solution in original post

2 REPLIES 2
v-caliao-msft
Microsoft Employee
Microsoft Employee

@kjsullivan,

 

Sample data and sample DAX expression for you reference.
Column = RANKX(FILTER(Table2,Table2[Country]=EARLIER(Table2[Country])),Table2[Amount],,DESC)
Capture.PNG

 

If this is not what you want, please provide us some sample data and your expected result, so that we can make further analysis.

 

Regards,

Charlie Liao

@v-caliao-msft

 

Thank you! That was exactly what I needed!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.