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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Create calculated Rank column in Powerbi

Hi all,

 

I have two tables- one is dimension and another is fact table. I want to calculate rank of users in Dim table based on sales in Fact table. It has to be in a calculated column.

 

Dim Table

 

CodeUSerTM
1Raj

A

2RaghavB

 

Fact Table

 

CodeSalesID
1300

1

12002
24003

 

I tried creating a column like 

 

 

sales = sum(Fact[Sales])
rank = RANKX(all(Dim),B[Fact])

 

 

 But it gave me 1 for all ranks.

Also When I used it in a calculated measure, it gave correct Ranks.

 

Request you to guide me.

 

Thanks

Garima Singh

@amitchandak 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

Please try:

Sales = 
VAR _codes = CALCULATETABLE(VALUES('User'[Code]),FILTER(ALL('User'),'User'[USer]=EARLIER('User'[USer])))
VAR _sales = CALCULATE(SUM('Sales'[Sales]),FILTER(ALL('Sales'),'Sales'[Code] IN _codes))
RETURN
_sales
Ranking = RANKX(ALL('User'),'User'[Sales],,DESC,Dense)

vcgaomsft_0-1673943108259.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

7 REPLIES 7
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file, whether it suits your requirement.

 

Jihwan_Kim_0-1673859670259.png

 

Jihwan_Kim_1-1673860903695.png

 

 

Rank CC =
VAR _sales =
    SUMX ( RELATEDTABLE ( Sales ), Sales[Sales] )
VAR _summaizetable =
    ADDCOLUMNS ( User, "@Sales", SUMX ( RELATEDTABLE ( Sales ), Sales[Sales] ) )
VAR _ranking =
    COUNTROWS ( FILTER ( _summaizetable, [@Sales] >= _sales ) )
RETURN
    _ranking

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

It works only when there is single record for a user in sales table. But in case there is multiple records then same user is repeated again and ranking is different.

 

garima_singh911_0-1673866648533.png

 

Table: Sales

CodeSalesID
13001
12002
24003
33004

 

User-

CodeUSerTM
1RajA
2RaghavB
3RajC

hi @Anonymous 

try to add a column like this:

SalesRank = 
RANKX(
    ALL(User[Code]), 
    CALCULATE(SUM(Sales[Sales]), ALLEXCEPT(User, User[Code]))
)

 

it worked like this:

FreemanZ_0-1673937659527.png

 

p.s. please consider @someone,  if you seek further suggestions.

 

Anonymous
Not applicable

Hi,

 

Thanks for the response. This is something we were able to achieve. But we want data to be reflected with distinct user and there rank at overall level. Not two rows for a user.

Something like:

 

UserSalesRank

Raj

8001
Raghav4002

hi @Anonymous 

just noticed your reply.  You may create a column like this:

SalesRank = 
RANKX(
    ALL(User[USer]), 
    CALCULATE(SUM(Sales[Sales]), ALLEXCEPT(User, User[USer]))
)

 

it worked like this:

FreemanZ_0-1673962528500.png

 

Anonymous
Not applicable

Hi @Anonymous ,

 

Please try:

Sales = 
VAR _codes = CALCULATETABLE(VALUES('User'[Code]),FILTER(ALL('User'),'User'[USer]=EARLIER('User'[USer])))
VAR _sales = CALCULATE(SUM('Sales'[Sales]),FILTER(ALL('Sales'),'Sales'[Code] IN _codes))
RETURN
_sales
Ranking = RANKX(ALL('User'),'User'[Sales],,DESC,Dense)

vcgaomsft_0-1673943108259.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Anonymous
Not applicable

Thankyou soo much! It worked 🙂

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors