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

Returning nth Ranked Item in a card

Hi, I have ranked my suppliers by sales with this RANKX function:

 

Supplier Rank = RANKX(ALL(Table[Supplier]),[Sales])
 
I want to be able to put the nth ranked item in a card (so essentially filtering on the RANKX measure). I can't create the rank in the table because I want the card to change depending on a location filter.
 
I tried this formula:
 
Top Supplier = CALCULATE(FIRSTNONBLANK(Table[Supplier],Table[Supplier]), FILTER(Table,[Supplier Rank] = 1))
 
but this just returns the first supplier alphabetically.
 
Any help would be appreciated.
1 ACCEPTED SOLUTION
Mariusz
Community Champion
Community Champion

Hi @Anonymous 

 

Try this measure.

 

Top Supplier = 
    TOPN( 1, ALL( Table[Supplier] ), [Sales] ) 

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
Mariusz Repczynski

 

View solution in original post

4 REPLIES 4
Mariusz
Community Champion
Community Champion

Hi @Anonymous 

 

Try this measure.

 

Top Supplier = 
    TOPN( 1, ALL( Table[Supplier] ), [Sales] ) 

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
Mariusz Repczynski

 

Anonymous
Not applicable

I have done something similar in my own workbook, and I have used these two measures:

Rank sales= 
VAR __items =
CALCULATE(
    COUNTROWS( Sales);
    FILTER(
        ALL( FactSales[Sales]);
        NOT( ISBLANK( [Sales (total)]))
    )
)
RETURN
IF(
    RANKX(
        ALL(FactSales);
        [Sales (total)]
    ) > __items;
    BLANK();
    RANKX(
        ALL(FactSales);
        [Sales (total)]
    )
)
title sales(top 1) = 
    CALCULATE(
        VALUES( FactSales[Sales]);
        FILTER(
            FactSales;
            [Rank sales] = 1
        )
    )

If it works then please mark it as the accepted solution.

Anonymous
Not applicable

Sorry - I have changed my code slightly and I have made some translation errors... It is not the FactSales table but the DimSalesItem table which I count and [Sales (total)] return the sum of sales from the FactTable.

 

The countrows return the number of items where there is a sale. This is done to ensure that only items with a sale get a rank, but this is probably not necessary in your case.

 

The measures should therefore be  (without the blank part):

RANKX(
    ALL(DimSalesItem);
    [Sales (total)]
)

title sales(top 1) = CALCULATE( VALUES( DimSalesItem[Item]); FILTER( DimSalesItem; [Rank sales] = 1 ) ) 

 

Anonymous
Not applicable

Sorry that formula didn't seem to work, I get a can't display visual error. Could you explain the logic behind what it is trying to do?

 

Thanks

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.