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
MrMonkeyMadness
Regular Visitor

How to get measure to show top ranking category?

Hello everyone,

 

I am having a bit of trouble with to referencing the top ranking Sales Category. I have created a measure which produces the ranking of categories based off sales:

 

RankSales =
RANKXALLSELECTED('Sales'[Category]), CALCULATE( SUM('Sales'[Sales Amount])),  DESCDense)
 
If I put Category and RankSales in a table, it produces the following:
MrMonkeyMadness_0-1637893583121.png

I want to create a measure which will tell us what is the top ranking Category (SALOON AND CAB), and another measure which shows the Sales Amount for that Category. 

 

Any tips?

 

 

 
 
2 ACCEPTED SOLUTIONS
VahidDM
Super User
Super User

HI @MrMonkeyMadness 

 

Try these measures

 

Category Top =
VAR _A =
    FILTER (
        ADDCOLUMNS (
            'Sales',
            "Rank",
                RANKX (
                    ALLSELECTED ( 'Sales'[Category] ),
                    CALCULATE ( SUM ( 'Sales'[Sales Amount] ) ),
                    ,
                    DESC,
                    DENSE
                )
        ),
        [Rank] = 1
    )
RETURN
    MAXX ( _A, [Category] )

 

 

and 

 

Sales Amount Top =
VAR _A =
    FILTER (
        ADDCOLUMNS (
            'Sales',
            "Rank",
                RANKX (
                    ALLSELECTED ( 'Sales'[Category] ),
                    CALCULATE ( SUM ( 'Sales'[Sales Amount] ) ),
                    ,
                    DESC,
                    DENSE
                )
        ),
        [Rank] = 1
    )
RETURN
    SUMX( _A, [Sales Amount] )

 

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

View solution in original post

Hi @MrMonkeyMadness 

 

You are welcome.

Change that ALLSELECTED ( 'Sales'[Category] ) to 'Sales' and check it then.

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

View solution in original post

3 REPLIES 3
MrMonkeyMadness
Regular Visitor

Hello VahidDM, 

 

Thank you for solving this.

 

Quick question, I am trying to filter the ranking for a certain period (say within the last 7 days). To do this, I am replacing your line of: 


CALCULATE ( SUM ( 'Sales'[Sales Amount] ))

 

with

 

CALCULATE ( SUM ( 'Sales'[Sales Amount] ), DATESINPERIOD('Sales'[DATE], TODAY(), -7, DAY)

 

The previously mentioned [RankSales] still shows 'Saloon and Cab' as the top rank but the measure doesn't seem to update the category as 'Saloon and Cab'.

 

Any thoughts? 

 

Thanks again for your time and efforts. 

 

Any thoughts? Thank you for your time and efforts. 

Hi @MrMonkeyMadness 

 

You are welcome.

Change that ALLSELECTED ( 'Sales'[Category] ) to 'Sales' and check it then.

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

VahidDM
Super User
Super User

HI @MrMonkeyMadness 

 

Try these measures

 

Category Top =
VAR _A =
    FILTER (
        ADDCOLUMNS (
            'Sales',
            "Rank",
                RANKX (
                    ALLSELECTED ( 'Sales'[Category] ),
                    CALCULATE ( SUM ( 'Sales'[Sales Amount] ) ),
                    ,
                    DESC,
                    DENSE
                )
        ),
        [Rank] = 1
    )
RETURN
    MAXX ( _A, [Category] )

 

 

and 

 

Sales Amount Top =
VAR _A =
    FILTER (
        ADDCOLUMNS (
            'Sales',
            "Rank",
                RANKX (
                    ALLSELECTED ( 'Sales'[Category] ),
                    CALCULATE ( SUM ( 'Sales'[Sales Amount] ) ),
                    ,
                    DESC,
                    DENSE
                )
        ),
        [Rank] = 1
    )
RETURN
    SUMX( _A, [Sales Amount] )

 

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

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.

Top Solution Authors