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
bssienes
Regular Visitor

RANX in ascending order

Hi All,

 

In my table I have companyName and featureName columns. I want to count rows in the table and rank based on featureName. This worked for me when I did ranking in descending order. Using the following code:

FeatureRank = RANKX(
        ALL('Features'[FeatureName]),
        CALCULATE(COUNTROWS('Features')),
        ,
        DESC
    )

However, If I do this in an ascending order, the output is not quiet what I expect in one scenario.
FeatureRank = RANKX(
        ALL('Features'[FeatureName]),
        CALCULATE(COUNTROWS('Features')),
        ,
        ASC
    )

For one of the companies I had all the features used (there are 11 features in total) so, it return the rank correctly in ascending order based on featureName. The ranks were changing from 1,2,3,...11 based on the number of times the featureNames occured.

However for another company I had only 3 featureNames. The rank that I received for these 3 features were 9,10 and 11. 
How do I get ranks 1,2,3 for the second company?

Note that I could have another company with different number of features used. How can I consistently rank the least used feature as 1 for each company?
1 REPLY 1
wdx223_Daniel
Super User
Super User

FeatureRank = RANKX(
        FILTER(ALL('Features'[FeatureName]),CALCULATE(COUNTROWS('Features'))),
        CALCULATE(COUNTROWS('Features')),
        ,
        ASC
    )

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.

Top Solution Authors