Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Issue with RANKX function with "Don't Summarize" option

I am facing the issue while ranking the data based on a "Date" column to get the top 2 categories for each category using the RANKX function. Below is the sample data:

I am getting the below output using this DAX measure:

RANK =
IF (
ISFILTERED( TestData[Period] )
&& HASONEVALUE( TestData[Date] ),
RANKX(
CALCULATETABLE(
VALUES( TestData[Date] ),
REMOVEFILTERS( TestData[Date] )
),
CALCULATE( VALUES( TestData[Date] ) )
)
)

 

 

The above measure didn't work as soon as I opted "don't summarize" option for any of the columns starting from AAA3-AAA11.
Can anybody let me know why this is happening?
Any help will be highly appreiciable

  • Hi, Anonymous 

    Create a measure 'Rank' as below, then sort by column rank:

    Rank =
    RANKX (
        GROUPBY ( ALLSELECTED ( 'TestData' ), TestData[Category], TestData[Date] ),
        RANKX (
            ALLSELECTED ( TestData ),
            CALCULATE ( MAX ( TestData[Category] ) ),
            ,
            ASC,
            DENSE
        )
            + RANKX (
                GROUPBY ( ALLSELECTED ( 'TestData' ), TestData[Category], TestData[Date] ),
                CALCULATE ( MAX ( 'TestData'[Date] ) ),
                ,
                ASC,
                DENSE
            )
                / CALCULATE ( COUNTROWS ( 'TestData' ), ALLSELECTED () ),
        ,
        ASC,
        DENSE
    )
    

    Please check my sample file for more details. If it doesn't work, share a pbix file on cloud storage for further research.

     

    Best Regards,
    Community Support Team _ Eason
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

11 Replies