Forum Discussion

MisterWLF's avatar
MisterWLF
Frequent Visitor
3 years ago

RANKX very slow performance

Dear community,

 

I want to carry out a Pareto analysis segmenting Suppliers in "A", "B" and "C" categories, based on a ranking of (cumulative) Spend per supplier:

 

A = largest suppliers, accounting for the first 80% of Spend

B = middle group of suppliers, accounting for next 15% of Spend

C = smallest suppliers, accounting for final 5% of Spend

 

To that end, I have used the below formula to assign the A, B or C to the suppliers, making use of RANKX:

 

ParetoAnalysisSegmentation =
VAR TotalSpend =    CALCULATE( [D_Spend_MaxYear] , ALL( DIM_Suppliers[Supplier name] ) )
VAR Ranking =       RANKX(
                        ALL( DIM_Suppliers[Supplier name] ) ,
                            DIVIDE( [D_Spend_MaxYear] , TotalSpend ) )
VAR Segmentation =  CALCULATE(
                        DIVIDE( [D_Spend_MaxYear] , TotalSpend ) ,
                            FILTER( ALL(  DIM_Suppliers[Supplier name] )  ,
                                RANKX(
                                    ALL(  DIM_Suppliers[Supplier name] ) ,
                                    DIVIDE( [D_Spend_MaxYear] , TotalSpend ) )
                                    <=
                                Ranking
                            )
                    )

RETURN
IF( [D_Spend_MaxYear] = BLANK() ,
    BLANK() ,
        SWITCH( TRUE() ,
            Segmentation <= 0.8 , "A" ,
            Segmentation <= 0.95 , "B" ,
            "C"
        )
)
 
Whereby measure [D_Spend_MaxYear] calculates Spend.
 
This formula works, however it is very, very slow (210 seconds according to Performance Analyzer). Any guidance on how to improve the performance of this formula? I think it has something to do with RANKX, but am at a loss on how to proceed. 
 
Any help is appreciated!

2 Replies

    • MisterWLF's avatar
      MisterWLF
      Frequent Visitor

      Hi Lucien, anonymized pbix file is here .

       

      Please use the column / measure names as included in the file. The expected outcome is already there, but as you can see the DAX is very slow. Any help on how to speed this up to a workable format is appreciated!