cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper I
Helper I

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

Accepted Solutions
Highlighted
Super User IV
Super User IV

Re: How to rank one column with 2 categories?

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/

 


______________


Has this post solved your problem? Please mark it as a 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.


I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query. 


excelwithallison.com

View solution in original post

Highlighted
Super User V
Super User V

Re: How to rank one column with 2 categories?

Hi @lauren1192 ,

 

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

Re: How to rank one column with 2 categories?

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/

 


______________


Has this post solved your problem? Please mark it as a 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.


I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query. 


excelwithallison.com

View solution in original post

Highlighted
Super User V
Super User V

Re: How to rank one column with 2 categories?

Hi @lauren1192 ,

 

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

Highlighted
Super User II
Super User II

Re: How to rank one column with 2 categories?

Hi @lauren1192,

what about the following solution:

 

05-07-_2020_23-33-54.jpg

 

Regards FrankAT

Helpful resources

Announcements
Meet the 2020 Season 2 Power BI Super Users!

Meet the 2020 Season 2 Power BI Super Users!

Find out who's part of the program this season, and welcome the new Super Users.

August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

July 2020 Community Highlights

July 2020 Community Highlights

Learn about the exciting things that happened in July.

Featured Data Story of The Month

Featured Data Story of The Month

All Data Stories Gallery contributions are reviewed for each month. We select a contribution and feature the community member the following month.

Power BI Dev Camp - Developing with .NET Core

Power BI Dev Camp - Developing with .NET Core

Learn how to develop custom web applications for Power BI using .NET Core 3.1 and .NET 5.

Top Solution Authors
Top Kudoed Authors