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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Amit92
Regular Visitor

Dynamic Rank Calculation

Hi Team

I have a model where i have Dim Market, Dim Brand and Fact Sales.
Market ID of Dim Market is connected to Market ID of Fact Sales
Brand ID of Dim Brand is connected to Brand ID of Fact Sales
We have a brand named "Kingfisher" in the Dim Brand

I need to create a measure with below logic:

Based on the slicer selection, I want the count of markets where the brand "Kingfisher" is coming on top 5 for a measure named Sales

In Short: 

Count the number of markets where “Kingfisher” appears in the Top 5 brands by Sales, respecting the current filter context.

Thanks
Amit
1 ACCEPTED SOLUTION
cengizhanarslan
Super User
Super User

Please try the measure below:

Kingfisher Top 5 Markets =
COUNTROWS (
    FILTER (
        VALUES ( 'Dim Market'[MarketID] ),
        VAR _KingfisherSales =
            CALCULATE (
                [Sales],
                'Dim Brand'[Brand] = "Kingfisher"
            )
        VAR _Rank =
            RANKX (
                ALLSELECTED ( 'Dim Brand'[Brand] ),
                CALCULATE ( [Sales] ),
                _KingfisherSales,
                DESC,
                Dense
            )
        RETURN
            _Rank <= 5
    )
)
_________________________________________________________
If this helped, ✓ Mark as Solution | Kudos appreciated
Connect on LinkedIn | Follow on Medium
AI-assisted tools are used solely for wording support. All conclusions are independently reviewed.

View solution in original post

4 REPLIES 4
cengizhanarslan
Super User
Super User

Please try the measure below:

Kingfisher Top 5 Markets =
COUNTROWS (
    FILTER (
        VALUES ( 'Dim Market'[MarketID] ),
        VAR _KingfisherSales =
            CALCULATE (
                [Sales],
                'Dim Brand'[Brand] = "Kingfisher"
            )
        VAR _Rank =
            RANKX (
                ALLSELECTED ( 'Dim Brand'[Brand] ),
                CALCULATE ( [Sales] ),
                _KingfisherSales,
                DESC,
                Dense
            )
        RETURN
            _Rank <= 5
    )
)
_________________________________________________________
If this helped, ✓ Mark as Solution | Kudos appreciated
Connect on LinkedIn | Follow on Medium
AI-assisted tools are used solely for wording support. All conclusions are independently reviewed.
johnt75
Super User
Super User

I think you can use

Num markets Kingfisher Top 5 =
VAR MarketsAndBrands =
    ADDCOLUMNS (
        CALCULATETABLE (
            SUMMARIZE ( Sales, Market[Market], Brand[Name] ),
            ALLSELECTED ()
        ),
        "@sales", [Sales]
    )
VAR Top5 =
    WINDOW (
        1,
        ABS,
        5,
        ABS,
        MarketsAndBrands,
        ORDERBY ( [@sales], DESC ),
        PARTITIONBY ( Market[Market] )
    )
VAR Result =
    COUNTROWS ( FILTER ( Top5, Brand[Name] = "Kingfisher" ) )
RETURN
    Result

Hi John,

Thanks for the quick help,
I am getting error in the above measure that the column Market[Market] specified in the 'SUMMARIZE' function was not found in the input table

 

Change both references to Market[Market] to whichever column from your market dimension uniquely identifies a row. e.g. you could use Market[Market ID].

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.