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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
BIMJ
Frequent Visitor

Ranking with condition to avoid blanks and certain values

I was trying to make a rank measure to take rank Customer based on their Sales. However, I need to avoid certain customers such as XXX and blank customers in the ranking or add them to a default ranking. Unfortunately, it is not working for me. Below is an example and the expected output as Rank.

 

CustomerSalesRank
E50001
C20002
XXX600 
B5003
 200 
Z1504
A1005
T506
R107

 

The dax calculation I am using is 

Rank =
IF (
SELECTEDVALUE ( Query1[Customer] ) IN { "XXX", "" }, -100, //applying default rank of -100
RANKX (
FILTER ( ALL ( Query1 ), NOT ( Query1[Customer] IN { "XXX", "" } ) ),
[Sales],
,
DESC
)
)

 

Please help

1 ACCEPTED SOLUTION
BIMJ
Frequent Visitor

I managed to frame the dax with the tips from @DataInsights . Thanks. Below is the final working solution 

 

Ranking Customers Asc =
IF (
    NOT MAX ( Query1[Customers] ) IN { "XXX"BLANK ()"" },
    //Filtering unwanted customers like XXX and blanks
    CALCULATE (
        RANKX ( ALL ( Query1[Customers] ), [Sales],, ASC, DENSE )
    ),
    //applying rank
    100 //giving default rank of 100 to unwanted customer
)

View solution in original post

4 REPLIES 4
BIMJ
Frequent Visitor

I managed to frame the dax with the tips from @DataInsights . Thanks. Below is the final working solution 

 

Ranking Customers Asc =
IF (
    NOT MAX ( Query1[Customers] ) IN { "XXX"BLANK ()"" },
    //Filtering unwanted customers like XXX and blanks
    CALCULATE (
        RANKX ( ALL ( Query1[Customers] ), [Sales],, ASC, DENSE )
    ),
    //applying rank
    100 //giving default rank of 100 to unwanted customer
)

DataInsights
Super User
Super User

@BIMJ,

 

Try this measure:

 

Rank = 
IF (
    NOT MAX ( Query1[Customer] ) IN { "XXX", "" },
    RANKX (
        FILTER ( ALL ( Query1 ), NOT Query1[Customer] IN { "XXX", "" } ),
        [Sales],
        ,
        DESC
    )
)

 

DataInsights_0-1662642341402.png

 





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

Proud to be a Super User!




Thank you for the help. Unfortunately, it is not working for me. The ranking is random. Please see below screenshot. I am checking on the worst profit (or loss) ranking. 

 

BIMJ_0-1662643978804.png

 

@BIMJ,

 

Please provide a sanitized pbix using one of the file services (e.g., OneDrive) and I'll look at it.





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

Proud to be a Super User!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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