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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

How to rank one column with 2 categories?

Hey,

 

Could someone please help me out with the following problem please?

 

I have 2 x categories with products in each and I want to rank product on value but if it is a new category I want this ranking to also start at 1.

From that I also want to add my respective categories to that product list and rank each category as 1.
 
This is so that I can plot, salad, fruit and their respective products on a graph. Then if I filter on top 3 for example it will show my desired output.
 
Table
CategoryProductValue
FruitApple9
FruitBanana8
FruitOrange7
SaladLettuce4
SaladTomato1
   
Desired Output
NEW ProductValueRank
Apple91
Banana82
Orange73
Lettuce41
Tomato12
Fruit241
Salad51
Does anyone have any ideas please?
 
Thank you in advance,
 
Lauren.
2 ACCEPTED SOLUTIONS
AllisonKennedy
Super User
Super User

You could try:

Use SUMMARIZECOLUMNS to create a new table of your desired output:

Table2=UNION(
SUMMARIZECOLUMNS(Table[Product], "Value", SUM(Table[Value]), "Rank",
RANKX(
ALL('Table'[Category]) ,
CALCULATE(
SUM('Table'[Value])
)
)),
SUMMARIZECOLUMNS(Table[Category], "Value", SUM(Table[Value]), "Rank", 1)

https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures

Or this will help get the ranks for the products only:

You could add a column to your table using RANKX, similar to this
Rank all rows as Column (Country) =
RANKX(
FILTER(
‘Table’,
‘Table'[Category] = EARLIER(‘Table'[Category])
),
‘Sales Table'[Value]
)
https://databear.com/how-to-use-the-dax-rankx-function-in-power-bi/

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

harshnathani
Community Champion
Community Champion

Hi @Anonymous ,

 

A little modification to the formula by @AllisonKennedy 

 

New Table =
UNION (
    SUMMARIZECOLUMNS (
        'Table'[Product],
        "Value", SUM ( 'Table'[Value] ),
        "Rank", IF (
            MAX ( 'Table'[Product] )
                <> BLANK (),
            RANKX (
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[Category]
                        = MAX ( 'Table'[Category] )
                ),
                CALCULATE (
                    SUM ( 'Table'[Value] )
                )
            )
        )
    ),
    SUMMARIZECOLUMNS (
        'Table'[Category],
        "Value", SUM ( 'Table'[Value] ),
        "Rank", IF (
            MAX ( 'Table'[Product] )
                <> BLANK (),
            RANKX (
                ALL ( 'Table'[Category] ),
                CALCULATE (
                    SUM ( 'Table'[Value] )
                )
            )
        )
    )
)

 

1.jpg

 

 

Regards,

Harsh Nathani


Appreciate with a Kudos!! (Click the Thumbs Up Button)

Did I answer your question? Mark my post as a solution!

View solution in original post

3 REPLIES 3
FrankAT
Community Champion
Community Champion

Hi @Anonymous,

what about the following solution:

 

05-07-_2020_23-33-54.jpg

 

Regards FrankAT

harshnathani
Community Champion
Community Champion

Hi @Anonymous ,

 

A little modification to the formula by @AllisonKennedy 

 

New Table =
UNION (
    SUMMARIZECOLUMNS (
        'Table'[Product],
        "Value", SUM ( 'Table'[Value] ),
        "Rank", IF (
            MAX ( 'Table'[Product] )
                <> BLANK (),
            RANKX (
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[Category]
                        = MAX ( 'Table'[Category] )
                ),
                CALCULATE (
                    SUM ( 'Table'[Value] )
                )
            )
        )
    ),
    SUMMARIZECOLUMNS (
        'Table'[Category],
        "Value", SUM ( 'Table'[Value] ),
        "Rank", IF (
            MAX ( 'Table'[Product] )
                <> BLANK (),
            RANKX (
                ALL ( 'Table'[Category] ),
                CALCULATE (
                    SUM ( 'Table'[Value] )
                )
            )
        )
    )
)

 

1.jpg

 

 

Regards,

Harsh Nathani


Appreciate with a Kudos!! (Click the Thumbs Up Button)

Did I answer your question? Mark my post as a solution!

AllisonKennedy
Super User
Super User

You could try:

Use SUMMARIZECOLUMNS to create a new table of your desired output:

Table2=UNION(
SUMMARIZECOLUMNS(Table[Product], "Value", SUM(Table[Value]), "Rank",
RANKX(
ALL('Table'[Category]) ,
CALCULATE(
SUM('Table'[Value])
)
)),
SUMMARIZECOLUMNS(Table[Category], "Value", SUM(Table[Value]), "Rank", 1)

https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures

Or this will help get the ranks for the products only:

You could add a column to your table using RANKX, similar to this
Rank all rows as Column (Country) =
RANKX(
FILTER(
‘Table’,
‘Table'[Category] = EARLIER(‘Table'[Category])
),
‘Sales Table'[Value]
)
https://databear.com/how-to-use-the-dax-rankx-function-in-power-bi/

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors