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
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 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
Super User
Super User

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
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.

Top Solution Authors