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

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.

Reply
milankRaj
Advocate I
Advocate I

Need to show Top 3 category and Top 3 subcategory when we apply drilldown. Not possible with TOPN

For Example, consider the below "Tickets" table which contains different categories and subcategories.

milankRaj_1-1601281921841.png

I am trying to show the top 2 categories in the bar chart and drill down by one of the top 2 categories, it should show the top 2 subcategories with the selected category. Please refer to the table and bar visual "Top 2 Category & Sub Category by Tickets" which should get the top 2 categories as well as the top 2 subcategories within the selected category.

As of now, it's not giving the expected output.

DAX :

ISCategory = COUNTROWS('Tickets') = CALCULATE(COUNTROWS('Tickets'),ALL('Tickets'), VALUES('Tickets'[category]))

----

CategoryRank =
IF (
[ISCategory],
RANKX ( ALLSELECTED ( 'Tickets'[category] ), [Ticket Count] ),
RANKX ( ALLSELECTED ( 'Tickets'[subcategory] ), [Ticket Count] )
)
milankRaj_0-1601283746053.png

 

Attaching the sample pbix for reference.

https://drive.google.com/file/d/1nm0fTtVSfmMDX1vZ4yG04VmsAWczyNcN/view?usp=sharing 

3 REPLIES 3
lbendlin
Super User
Super User

you're pretty close, but you need to use nested RANKX, not alternating RANKX if you want to show the top two subcategories inside each of the top two categories.

Could you help me by sending the the DAX for Nested RANKX with the pbix shared?

Here is one implementation

 

 

CR := RANKX(ALL(Tickets[category]),CALCULATE(sum(Tickets[number]),all(Tickets[subcategory])))

SCR := RANKX(Filter(ALL(Tickets[category],Tickets[subcategory]),Tickets[category]=max(Tickets[category])),CALCULATE(sum(Tickets[number])))

 

 

This will pull the first two categories, and then the first two subcategories for these categories (if you set filters for CR<3 and SCR<3)

 

Also refer to this explanation: https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures

 

 

lbendlin_0-1601389828198.png

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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