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
arielcedola
Helper III
Helper III

Ranking of items in 3 subcategories

Hi,

I need some measurements to get the ranking of the different items within some subcategories (Area/Product/Article), and also the top ranked item in each ranking. The ranking in a given subcategory must be filtered by the top ranked item in the upper one.

This is the sample dataset. There are 2 items in Area, 4 Products within each Area, and 3 different Articles for each Product:

table shops3.png

For example, if the top ranked Area is Audio, I need to know the top ranked audio Product (from Headphones, Hi-Fi, Mic, MP3), and for this product (let's say for example Headphones) the top ranked article (from Headph_1, Headph_2 and Headph_3 in this case).

I have to show the 3 rankings in 3 separate tables or matrices, and the top ranked items in cards.

Area, Product and Article must be ranked by sum of ArticleNSales, ProductMeanProfit and ArticleNSales, respectively.

Here the link to the file, thanks in advance!

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

1 ACCEPTED SOLUTION
v-yingjl
Community Support
Community Support

Hi @arielcedola ,

You can create the following measures:

Rank Area = RANKX( ALLSELECTED(Sales[Area]), CALCULATE(SUM(Sales[ArticleNSales])),,DESC,Dense)
Rank Product = 
VAR a =
    CALCULATETABLE(FILTER ( DISTINCT ( 'Sales'[Area] ), [Rank Area] = 1 ),ALLSELECTED())
RETURN
    IF (
        CALCULATE ( COUNTROWS ( 'Sales' ), 'Sales'[Area] IN a ) = 0,
        BLANK (),
        RANKX (
            GROUPBY (
                FILTER ( ALLSELECTED ( 'Sales' ), 'Sales'[Area] IN a ),
                'Sales'[Product]
            ),
            CALCULATE ( SUM ( 'Sales'[ProductMeanProfit] ), 'Sales'[Area] IN a ),
            ,
            DESC,
            DENSE
        )
    )
Rank Article = 
VAR a =
    CALCULATETABLE(FILTER ( DISTINCT ( 'Sales'[Product] ), [Rank Product] = 1 ),ALLSELECTED())
RETURN
    IF (
        CALCULATE ( COUNTROWS ( 'Sales' ), 'Sales'[Product] IN a ) = 0,
        BLANK (),
        RANKX (
            GROUPBY (
                FILTER ( ALLSELECTED ( 'Sales' ), 'Sales'[Product] IN a ),
                'Sales'[Article]
            ),
            CALCULATE ( SUM ( 'Sales'[ArticleNSales] ), 'Sales'[Product] IN a ),
            ,
            DESC,
            DENSE
        )
    )

In table 2 and table 3, set the value of second and third measure is not blank in the table visual filter and you will get your expected result:

table visual.png

result.png

 

Sample file is attached that hopes to help you, please check and try it: Ranking of items in 3 subcategories.pbix 

 

Best Regards,
Yingjie Li

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
Syndicate_Admin
Administrator
Administrator

Hello

I need some measurements to get the ranking of the different items within some subcategories (area/product/item), and also the top ranked item in each ranking. The rank of a given subcategory should be filtered by the highest ranked item at the top.

Here's the sample dataset. There are 2 items in the area, 4 products within each area and 3 different items for each product:

table shops3.png

For example, if the highest ranked area is Audio, I need to know the highest ranked audio product (headphones, hi-fi, microphone, MP3), and for this product (say for example headphones) the highest ranked item (from Headph_1, Headph_2 and Headph_3 in this case).

I have to show the 3 rankings in 3 separate tables or matrices, and the top-ranked items on the cards.

Area, Product, and Article must be sorted by the sum of ArticleNSales, ProductMeanProfit, and ArticleNSales, respectively.

Here the link to the file, thanks in advance!

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

v-yingjl
Community Support
Community Support

Hi @arielcedola ,

You can create the following measures:

Rank Area = RANKX( ALLSELECTED(Sales[Area]), CALCULATE(SUM(Sales[ArticleNSales])),,DESC,Dense)
Rank Product = 
VAR a =
    CALCULATETABLE(FILTER ( DISTINCT ( 'Sales'[Area] ), [Rank Area] = 1 ),ALLSELECTED())
RETURN
    IF (
        CALCULATE ( COUNTROWS ( 'Sales' ), 'Sales'[Area] IN a ) = 0,
        BLANK (),
        RANKX (
            GROUPBY (
                FILTER ( ALLSELECTED ( 'Sales' ), 'Sales'[Area] IN a ),
                'Sales'[Product]
            ),
            CALCULATE ( SUM ( 'Sales'[ProductMeanProfit] ), 'Sales'[Area] IN a ),
            ,
            DESC,
            DENSE
        )
    )
Rank Article = 
VAR a =
    CALCULATETABLE(FILTER ( DISTINCT ( 'Sales'[Product] ), [Rank Product] = 1 ),ALLSELECTED())
RETURN
    IF (
        CALCULATE ( COUNTROWS ( 'Sales' ), 'Sales'[Product] IN a ) = 0,
        BLANK (),
        RANKX (
            GROUPBY (
                FILTER ( ALLSELECTED ( 'Sales' ), 'Sales'[Product] IN a ),
                'Sales'[Article]
            ),
            CALCULATE ( SUM ( 'Sales'[ArticleNSales] ), 'Sales'[Product] IN a ),
            ,
            DESC,
            DENSE
        )
    )

In table 2 and table 3, set the value of second and third measure is not blank in the table visual filter and you will get your expected result:

table visual.png

result.png

 

Sample file is attached that hopes to help you, please check and try it: Ranking of items in 3 subcategories.pbix 

 

Best Regards,
Yingjie Li

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-yingjl 

Great solution, thanks a lot!

Best 😉

harshnathani
Community Champion
Community Champion

Hi @arielcedola ,

 

You can create the following measures.

Rank Area =
RANKX (
    ALLSELECTED ( Sales[Area] ),
    CALCULATE (
        SUM ( Sales[ArticleNSales] )
    ),
    ,
    DESC
)

 

Rank Article = RANKX( ALLSELECTED(Sales[Article]), CALCULATE(SUM(Sales[ArticleNSales])),,DESC)
 
Rank Product = RANKX( ALLSELECTED(Sales[Product]), CALCULATE(SUM(Sales[ProductMeanProfit])),,DESC)

 

 

 

Please find pbix attached :

https://drive.google.com/open?id=1lVIFoxJkBlTMGPPbyF7-4AQY7-zPXME6

 

1.jpg

 

 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

 

Hi @harshnathani 
thanks a lot for your quick response!
There is still something to adjust, because as I exposed in the question I need to rank each subcategory filtering by the top ranked item in the category above.
If you check the file you sent me, for example for Shop A the top Area is Video but the resulting top Product belongs to Audio (Headphones). Actually in the second table just the 4 products belonging to Video should be ranked (because Video is the top ranked Area), whereas in the third ranking just the 3 articles belonging to the top ranked Product should appear.
This filtering should be introduced in the DAX formulas (not in the visual level filter of the tables).
Thanks again!

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.