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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
HaNguyen97
Frequent Visitor

How to calculate RANK correctly when there is filter

I have data like this:

SegmentClientSale Amount
Aac100
Aab10
Abd200
Bac30
Bab40
End300
Dac250
Dab10
Dns30
Dnd20
Fbd300
Fac100

 

First, I need to calculate rank of Segment based on total Sales Amount.

Expected result is

SegmentClientSale AmountRank
Aac1002
Aab102
Abd2002
Bac304
Bab404
End3003
Dac2502
Dab102
Dns302
Dnd202
Fbd3001
Fac100

1

When apply filter on Client, the total amount will need to changed accordingly.

For example, when I select client "ac" or "ab", expected result is

SegmentClientSale AmountRank
Aac1002
Aab102
Bac304
Bab404
Dac2501
Dab101
Fac100

3

How to achive this?

1 ACCEPTED SOLUTION
rajendraongole1
Super User
Super User

Hi @HaNguyen97  - Create a measure to calculate the total sales for each segment.

 

Eg: Total Sales by Segment =
CALCULATE(
SUM('SalesTable'[Sale Amount]),
ALLEXCEPT('SalesTable', 'SalesTable'[Segment])
)

 

Now create an another measure to rank the segments based on the total sales calculated.

Rank by Segment Sales =
RANKX(
ALLSELECTED('SalesTable'[Segment]),
[Total Sales by Segment],
,
DESC,
DENSE
)

 

Hope it works and now add these measures to your visualization in Power BI report 

 

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

1 REPLY 1
rajendraongole1
Super User
Super User

Hi @HaNguyen97  - Create a measure to calculate the total sales for each segment.

 

Eg: Total Sales by Segment =
CALCULATE(
SUM('SalesTable'[Sale Amount]),
ALLEXCEPT('SalesTable', 'SalesTable'[Segment])
)

 

Now create an another measure to rank the segments based on the total sales calculated.

Rank by Segment Sales =
RANKX(
ALLSELECTED('SalesTable'[Segment]),
[Total Sales by Segment],
,
DESC,
DENSE
)

 

Hope it works and now add these measures to your visualization in Power BI report 

 

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





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.