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
Anonymous
Not applicable

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 @Anonymous ,

 

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
Community Champion
Community Champion

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

Anonymous
Not applicable

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 @Anonymous ,

 

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