Forum Discussion

SBC's avatar
SBC
Helper III
1 year ago
Solved

How to Generate Unique Ranks in Power BI Table Visual

Hello Community,

I am working on a Power BI report where I need to generate unique ranks in a table visual. The ranking is based on a measure from one table (Table2) and a column from another table (Table1). Below is the detailed scenario:

  • Table1 contains the UserID column.
  • Table2 contains session data, and I have created a measure called [Sessions] that calculates the number of sessions for each user.
  • There is an established relationship between UserID in Table1 and the session data in Table2.

Requirements:

  1. I want to rank users based on the [Sessions] measure in descending order, where the user with the highest session count gets rank 1.
  2. If two or more users have the same session count, they should still receive different ranks (i.e., no ties).
  3. The ranking should be dynamic and update based on filters applied in the report.
  4. The ranking should be displayed in a table visual.

    Sample Data:

    • Table1 (UserID):

      UserID
      Alice
      Bob
      Carol
      Dave
      Eve
    • Table2 (Sessions):
      • The [Sessions] measure calculates session duration or count for each user.

    Expected Output Table visual:

           
    UserIDSessionsRank_Sessions
    Dave      60        1
    Bob452
    Alice303
    Eve304
    Carol205
    As you can see, even though Alice and Eve have the same session count (30), they are assigned different ranks (3 and 4, respectively) to ensure uniqueness.

    Current DAX Logic:

    This is the current DAX logic I am using to generate ranks:
    text
    Rank_Sessions =   IF( ISINSCOPE('Table1'[UserID]), RANKX( ALL('Table1'), [Sessions], , DESC, DENSE ), BLANK() )

    Issue:

    This formula works for generating ranks but does not handle ties well when multiple users have the same session count. I need help modifying this logic so that when two users have identical session counts, they are still assigned different ranks (i.e., no ties).Any suggestions or improvements would be greatly appreciated!Thanks,SBC

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi SBC ,
    Try by using this way like by replacing rank with rownumber, i hope it works 

     

    • SBC's avatar
      SBC
      Helper III

      Hi Anonymous ,

       thanks for responding. The session is actually a measure from one table2, and the user ID is from a different table, which is a column in Table 1. I'm having trouble applying the logic you provided.

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        Then you can merge the two tables on User ID and then apply the dax which i shared
        or
        else use the related function and try adding the sessions column into table 1 and then apply it will works for you (link for how to apply related : https://youtu.be/8YJyALHRKRY?si=kVrp91C110j6u34d)
        Hope it will work for you
        or else explain it clearly what you are not getting then i will help you