Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

Medida Acumulada Ranck

 

Buenos dias,

Requiero hacer una medica acumulada de los clientes con mayor ventas al menor, tienen idea de como hacerlo?

 

 

1 Reply

  • Hi Anonymous ,

     

    Create a ranking table with the following code:

    Ranking = GENERATESERIES(1;100;1)

     

    Now create the following 4 measures:

    Ranking = SELECTEDVALUE(Ranking[Ranking Index])
    
    Top Customers =
    CALCULATE (
        SELECTEDVALUE ( 'Table'[Customer]; BLANK () );
        FILTER (
            VALUES ( 'Table'[Customer] );
            RANKX ( ALL ( 'Table' ); [Total Sales] ) = [Ranking]
        )
    )
    
    Customer Sales =
    CALCULATE (
        [Total Sales];
        FILTER ( VALUES ( 'Table'[Customer] ); 'Table'[Customer] = [Top Customers] )
    )
    
    Cumulative Totals =
    VAR CurrentRank =
        RANKX ( ALL ( 'Table' ); [Total Sales];; DESC )
    VAR IndexRank = [Ranking]
    RETURN
        IF (
            [Top Customers] = BLANK ();
            BLANK ();
            SUMX (
                FILTER (
                    SUMMARIZE (
                        'Table';
                        'Table'[Customer];
                        "@Sales"; [Total Sales];
                        "@Ranking"; RANKX ( ALL ( 'Table' ); [Total Sales] )
                    );
                    [@Ranking] <= IndexRank
                );
                [@Sales]
            )
        )

     

    Now just add the values to a table visualization.

     

    Check PBIX file attach.