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

Find rank or percentile for a group

Hello All , I am a beginner in Power BI. I am trying to build a dashboard with following data - 

 

Data - 

Product_IDCompetitorPriceDate
ABC1F100Jan-19
ABC1XYZ60Jan-19
ABC1A10Jan-19
ABC1M40Jan-19
ABC1B41Jan-19
PQR3F16Mar-19
PQR3XYZ75Mar-19
PQR3A156Mar-19
PQR3M23Mar-19
PQR3B121Mar-19
ABC1F102Mar-19
ABC1XYZ98Mar-19
ABC1A109Mar-19
ABC1M46Mar-19
ABC1B12Mar-19
ABC1R19Mar-19
ABC1D156Mar-19

 

Problem-
I want to find percentile rank for the competitior XYZ for each Product_ID based on price with date as a filter. Desired output should look like below - 

 

Date Filter : Mar-19

 

DESIRED OUTPUT : 

 

Product_IDPercentile
ABC10.57
PQR30.6

 

Notes - 

0.57 because XYZ is placed at 4th out of 7 competitors. So 4/7=0.57

0.6 because XYZ is placed at 3rd out of 5 competitors. So 3/5=0.6

 

Could someone help me ? 

 

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario.

Table:

f1.png

 

Then you may create a calculated column and a measure as follows.

 

calculated column
ColumnRank = 
RANKX(
    FILTER(
        ALL('Table'),
        'Table'[Product_ID] = EARLIER('Table'[Product_ID])&&
        'Table'[Date] = EARLIER('Table'[Date])
    ),
    'Table'[Price],
    ,DESC
)

measure:
Percentile = 
var _currentid = MAX('Table'[Product_ID])
return
DIVIDE(
    CALCULATE(
        SUM('Table'[ColumnRank]),
        FILTER(
            'Table',
            'Table'[Product_ID] = _currentid&&
            'Table'[Competitor] = "XYZ"
        )
    ),
    CALCULATE(
        MAX('Table'[ColumnRank]),
        FILTER(
            'Table',
            'Table'[Product_ID] = _currentid
        )
    )
)

 

 

Result:

f2.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
joyhackett
Helper II
Helper II

I am having a very similiar issue but my original table is not summarized by ProductID (as in the example in the OP).  

 

Is there a way to summarize the table as a calculated variable table first and then apply your logic?  My problem is that I cannot create a Calculated Column with the RankX - it has to be a measure as it is ranking on the SUM of Price.

 

@v-alq-msft

v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario.

Table:

f1.png

 

Then you may create a calculated column and a measure as follows.

 

calculated column
ColumnRank = 
RANKX(
    FILTER(
        ALL('Table'),
        'Table'[Product_ID] = EARLIER('Table'[Product_ID])&&
        'Table'[Date] = EARLIER('Table'[Date])
    ),
    'Table'[Price],
    ,DESC
)

measure:
Percentile = 
var _currentid = MAX('Table'[Product_ID])
return
DIVIDE(
    CALCULATE(
        SUM('Table'[ColumnRank]),
        FILTER(
            'Table',
            'Table'[Product_ID] = _currentid&&
            'Table'[Competitor] = "XYZ"
        )
    ),
    CALCULATE(
        MAX('Table'[ColumnRank]),
        FILTER(
            'Table',
            'Table'[Product_ID] = _currentid
        )
    )
)

 

 

Result:

f2.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thanks @v-alq-msft  , this worked like a charm. Could you explain the methodology you used ?

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.