Forum Discussion

bssienes's avatar
bssienes
Regular Visitor
3 years ago

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

  • wdx223_Daniel's avatar
    wdx223_Daniel
    Icon for Community Champion rankCommunity Champion
    FeatureRank = RANKX(
            FILTER(ALL('Features'[FeatureName]),CALCULATE(COUNTROWS('Features'))),
            CALCULATE(COUNTROWS('Features')),
            ,
            ASC
        )