cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rafael_pereira
Frequent Visitor

Top N Categories within the Nth Category

Hello,

I would like to request help from the community, I have a database that has categories and subcategories. As below:

 

CategorySubcategoryValue
AA1-1000
AA2-256
AA3-100
AA420
BB1-320
BB2-152
BB3-5
CC1-73
CC210

 

 

what I would like is within each Nth category, sort a list with the top N of the subcategories using DAX.


1 ACCEPTED SOLUTION

Hi @rafael_pereira ,

 

Please check:

3.png

 

Best Regards,

Stephen Tao

 

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

4 REPLIES 4
CNENFRNL
Super User
Super User

RANK_SUB = 
RANKX(
    FILTER(
        ALLSELECTED( 'DATASET'[Subcategory] ),
        NOT ISEMPTY(
            CALCULATETABLE(
                'DATASET',
                ALLEXCEPT( 'DATASET', 'DATASET'[Category], 'DATASET'[Subcategory] )
            )
        )
    ),
    CALCULATE(
        SUM( 'DATASET'[Value] ),
        ALLEXCEPT( 'DATASET', 'DATASET'[Category], 'DATASET'[Subcategory] )
    )
)

Screenshot 2021-11-06 041655.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is beyond their comprehension!

DAX is simple, but NOT EASY!

AlexisOlson
Super User
Super User

It would help if you show what the end result should be.

Thanks for the answers,

I tried to assemble what I'm trying to assemble, the yellow part would be cards and the green part, tables or matrices. Note that between the categories (from left to right) there is an order from largest to smallest (if you consider the sum) and within the categories as well.Captura de tela 2021-11-06 082357.png Thank you for your support!

Hi @rafael_pereira ,

 

Please check:

3.png

 

Best Regards,

Stephen Tao

 

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

Helpful resources

Announcements
Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

charticulator_carousel_with_text (1).png

Charticulator Design Challenge

Put your data visualization and design skills to the test! This exciting challenge is happening now through May 31st!

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Power BI Release May 2022 768x460.png

Check it out!

Click here to read more about the May 2022 updates!