Forum Discussion

shaunwilks's avatar
shaunwilks
Helper V
2 years ago
Solved

RANKX Calculated Column on a Related Tables

Sorry to have had to raise this request but I have looked far and wide for a resolution and tried perhaps 20 different DAX formulas for RANKX without the result I am looking for.  I have used samples...
  • SamInogic's avatar
    2 years ago

    Hi,

     

    We are a bit unclear about your requirement; if you can provide us the expected result, it will help us better to create DAX expressions.

    However, as per our understanding, you want ranking based on players' scores across different criteria. Here’s how you can achieve this using DAX in:

    Step 1: Create uniqueKey Keys

    First, create a uniqueKey key in both the Players and Games tables to help with the relationships.

    uniqueKey= [Player] & "-" & [Year] & "-" & [Team] 

    Step 2: Create Relationships

    1. Go to the Model View in Power BI.
    2. Create a relationship between the uniqueKey column in the Players table and the uniqueKey column in the Games table.

     

    Step 3: Create Measures and Calculated Columns

    Total Points Measure

    Create a measure to calculate the total points for each player:

    TotalPoints = SUM(Games[Points])

    Player Total Points

    Create a calculated column in the Players table to calculate the total points for each player:

    PlayerTotalPoints = CALCULATE(    [TotalPoints],    FILTER(        Games,        Games[uniqueKey] = Players[uniqueKey]    ))

    All-Time Rank

    Create a calculated column in the Players table for the all-time score rank:

    AllTimeRank = RANKX(    ALL(Players),    [PlayerTotalPoints],    ,    DESC,    DENSE)

    Rank Within Year

    Create a calculated column in the Players table for the rank within a specific year:

    RankWithinYear = RANKX(    FILTER(        ALL(Players),        Players[Year] = EARLIER(Players[Year])    ),    [PlayerTotalPoints],    ,    DESC,    DENSE)

    Rank Within Year and Team

    Create a calculated column in the Players table for the rank within a specific year and team:

    RankWithinYearAndTeam = RANKX(    FILTER(        ALL(Players),        Players[Year] = EARLIER(Players[Year]) &&        Players[Team] = EARLIER(Players[Team])    ),    [PlayerTotalPoints],    ,    DESC,    DENSE) 

     

    Please refer to the screenshot below for the results, 

     

    Hope this helps.

     

    Thanks!