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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
akarasick1
Frequent Visitor

RANKX and visual level filter

I have a table containing locations [tLocation], another related table containing products [tProduct]. I want to be able to select a single location in a visual filter and see a rank (as a card) of unique product types for that location. New York has two unique product types, and should rank 1 if selected. If Los Angeles or Houston is selected, they have one unique type and should rank as 2. If Chicago is selected, no types and rank of 3. How can I build measures for distinctcount and rank where the count and rank will work whether a selection is made in a filter dropdown or if all are selected.

 

Location
New York
Los Angeles
Chicago

Houston

 

ProductType
Location
ARedNew York
ARedLos Angeles
ARedHouston
BRedNew York
BRedLos Angeles
BRedHouston
CRedNew York
CRedLos Angeles
DBlueNew York
1 ACCEPTED SOLUTION
littlemojopuppy
Community Champion
Community Champion

Hi @akarasick1 

 

Two measures...

Product Count = COUNTROWS(Products)

Product Ranking = 
    RANKX(
        ALL(Locations),
        [Product Count],
        [Product Count],
        DESC,
        Skip
    )

 

littlemojopuppy_0-1609971713619.png

You should be able to drop the Product Ranking measure into a card.  Hope this helps!🙂

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@akarasick1 , Try Rank like a new measure

rankx(allselected(Table), calculate(DistinctCount(Table[Product])),,desc,dense)

 

For Rank Refer these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale
https://community.powerbi.com/t5/Community-Blog/Dynamic-TopN-made-easy-with-What-If-Parameter/ba-p/3...

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak I posted a response to this four hours ago with a screen shot showing that the solution I offered works@AlB offered a solution before I did (I started working on this while there were no responses).  Why did you feel that another solution was necessary???

littlemojopuppy
Community Champion
Community Champion

Hi @akarasick1 

 

Two measures...

Product Count = COUNTROWS(Products)

Product Ranking = 
    RANKX(
        ALL(Locations),
        [Product Count],
        [Product Count],
        DESC,
        Skip
    )

 

littlemojopuppy_0-1609971713619.png

You should be able to drop the Product Ranking measure into a card.  Hope this helps!🙂

AlB
Community Champion
Community Champion

Hi @akarasick1 

Try this measure in a card visual:

 

Rank measure = 
RANKX(ALL(tLocation[Location]), CALCULATE(DISTINCTCOUNT(tProduct[Type])),,DESC,Dense)

 

 See it all at work in the attached file.

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.