Forum Discussion

selected_'s avatar
selected_
Icon for Helper IV rankHelper IV
5 years ago
Solved

create index with measure

I'm trying to create a calculated column like 

Index = RANKX(ALL(table),table[random_column],,ASC)
 
but it does not give me unique index like 1,2,3,4, like the one you can do in power query instead I get 1,1,1,2,2,4,4,3,
 
In same time I also wonder if you save performance to work in the power query than do calculated measures and columns?
  • Hi selected_ ,

     

    For the rankx function, the basis for processing the same ranking, skip stands for sparse ranking, and the next ranking is equal to the number of all previous rankings + 1; dense stands for dense ranking, which only accumulates the ranking, regardless of the number. 


    Therefore, only the following two results can be obtained for the rank function. If you want to get a continuous and uninterrupted ranking. You can create a column index after sorting to get the desired result.

     

    C1 = RANKX('Table (2)',[Value],,ASC,Dense)
    C2 = RANKX('Table (2)',[Value],,ASC,Skip)

     

     

    You can use the Performance Analyzer to view the operating status of the created calculated column and measure to optimize. 

    related document link: Use Performance Analyzer to examine report element performance in Power BI Desktop - Power BI | Microsoft Docs


    Best Regards,
    Henry

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

5 Replies

  • v-henryk-mstf's avatar
    v-henryk-mstf
    Icon for Community Support rankCommunity Support

    Hi selected_ ,

     

    For the rankx function, the basis for processing the same ranking, skip stands for sparse ranking, and the next ranking is equal to the number of all previous rankings + 1; dense stands for dense ranking, which only accumulates the ranking, regardless of the number. 


    Therefore, only the following two results can be obtained for the rank function. If you want to get a continuous and uninterrupted ranking. You can create a column index after sorting to get the desired result.

     

    C1 = RANKX('Table (2)',[Value],,ASC,Dense)
    C2 = RANKX('Table (2)',[Value],,ASC,Skip)

     

     

    You can use the Performance Analyzer to view the operating status of the created calculated column and measure to optimize. 

    related document link: Use Performance Analyzer to examine report element performance in Power BI Desktop - Power BI | Microsoft Docs


    Best Regards,
    Henry

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi @selected_ .

    You can use the following DAX to create a calculated Index Column,

     

    Index=
    RANKX(
    FILTER(table,
    EARLIER(table[random_column])>table[random_column]),
    table[value column],,ASC)

     

    Regards,

    Sanket Bhagwat.

     

    If this posts helps , then please mark it as 'Accept As Solution' and give it a big thumbs up.

    • selected_'s avatar
      selected_
      Icon for Helper IV rankHelper IV

      Same issue, I get same value back as 1,1,1,1,1,2,2,2,3,3,4 

       

      I need unique index column for all rows.

      • Anonymous's avatar
        Anonymous
        Not applicable

        Can you please share your sample data?