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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
ChrisWilliams
Advocate II
Advocate II

Rankx with filter

I'm working on a RANKX function that involves a filter.  I reviewed this answer, but it did not seem to help my scenario.

 

I have a table called "UserMessages", and a simplified version is shown below:

 

table.PNG

 

Basically, I want to rank users as "Top Senders" or "Top Receivers".  When they are a Top Sender, we are ranking based on filtering the Direction column to "Outbound".

 

I created a message called "Rank Top Senders" and it looks like this:

 

Rank Top Senders = RANKX(FILTER(ALL(UserMessages), UserMessages[Direction] = "Outbound"), SUM(UserMessages[Messages]),,DESC,Dense)

 

However, it doesn't appear to rank correctly, because each user is shown with a rank of 1

result.PNG

 

I've tried several variations, but if someone can point me in the right direction I'd appreciate it.

1 ACCEPTED SOLUTION
Vvelarde
Community Champion
Community Champion

hi @ChrisWilliams

 

Rank Top Senders =
RANKX (
    FILTER ( ALL ( UserMessages ); UserMessages[Direction] = "Outbound" );
    CALCULATE (
        SUM ( UserMessages[Messages] );
        ALLEXCEPT ( UserMessages; UserMessages[User] )
    );
    ;
    DESC;
    DENSE
)

 

replace ; with ,




Lima - Peru

View solution in original post

7 REPLIES 7
Vvelarde
Community Champion
Community Champion

hi @ChrisWilliams

 

Rank Top Senders =
RANKX (
    FILTER ( ALL ( UserMessages ); UserMessages[Direction] = "Outbound" );
    CALCULATE (
        SUM ( UserMessages[Messages] );
        ALLEXCEPT ( UserMessages; UserMessages[User] )
    );
    ;
    DESC;
    DENSE
)

 

replace ; with ,




Lima - Peru
Anonymous
Not applicable

Hi Chris,

 

I have been searching for help on my challenge and run into this post. I tried to modify your solution to my situation but it is not working somehow. My situation is a little bit different.

 

A simplified table is below. What I want is to rank the Customer Name by Sales BUT EXCLUDING all the Customers with Blank names (let's call them anyomymous customers). 

 

The formula I came up after modelling yours is:

Rank Customer By Sales= RANKX(
filter(all(Table[Customer Name]),NOT(ISBLANK(Table[Customer Name]))),
CALCULATE(sum(Sales), ALLEXCEPT(Customer Name])),,DESC,Dense)
 
But it is still including the Anonymous customers. 

 

Thanks for help. 

 

PBISean

 

Customer NameSalesSales Order Num
A8001
B7002
C6003
D5004
E4005
 3006
F2007
G1008
A809
B7010
C6011
D5012
E4013
 3014
F2015
G1016

Hi,

 

You may drag Customer Name to the row labels and then in the Visual level filters, uncheck the blank in the Customer Name field.  Write these measures

 

Total Sales = SUM(Data[Sales])

Rank of selected Customers = RANKX(ALLSELECTED(Data[Customer Name]),[Total sales])
 
Hope this helps.

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Ashish_Mathur,

 

Thanks for your help. It works on my mock data, but not working on my real data set which has 1.3M lines. Not sure why. I will spend some time tomorrow trying to trouble shoot. I just want to thank you first. 

 

PBISean

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Anonymous

 

Hi, a simple way is using a measure to Rank (Basic) and a Visual Level Filter to exclude Blanks.

 

If you have problems with the filter you can create a new measure

 

MeasuretoexcludeAnonymus=Len(Table1[ClientName])

 

and use it in the visual level filter to exclude the 0.

 

Regards

 

Victor




Lima - Peru

 Thank you @Vvelarde, that works perfectly.  I'll have to study up on AllExcept... I haven't seen that used in Ranking before but it works well.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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