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

    • Anonymous's avatar
      Anonymous
      Not applicable

      amitchandak - Amit I need the top two categories based on date only.

      For that, I need a RANK measure.

      • amitchandak's avatar
        amitchandak
        Icon for Super User rankSuper User

        Anonymous , Create a measure like this and use that in the visual level filter to check <=2

         

        countx(filter(allselected(Table), Table[Category] = max(Table[Category]) && Table[Date] <= max(Table[Date])),Table[Date])

         

  • Anonymous's avatar
    Anonymous
    Not applicable

    amitchandak - Thank you so much. It's working now for me. Can you please explain this to me to understand?

  • Anonymous's avatar
    Anonymous
    Not applicable

    amitchandak - Amit Thanks for your help. As of now, it's working for me. Along with this, I want to sort one of the columns based on another column before giving the rank. Can you help me in that?

      • Anonymous's avatar
        Anonymous
        Not applicable

        amitchandak - I have gone through this article as well before but in my case, I need to sort a column within a category as I was trying to get the rank within categories.

    • Anonymous's avatar
      Anonymous
      Not applicable

      amitchandak - Amit can you help me to sort the data within the group as well?

      • v-easonf-msft's avatar
        v-easonf-msft
        Icon for Community Support rankCommunity Support

        Hi, Anonymous 

        You need to sort column 'Category' first, then hold down 'Shift' and click another column (column'Date'/column'Rank') for secondary sorting.

         

        Best Regards,
        Community Support Team _ Eason