Forum Discussion

JoseCamp's avatar
JoseCamp
Frequent Visitor
5 years ago
Solved

Repeat rank value through hierarchy levels

Hello community,    I have a product table with different sizes and locations (Table on the left). I have created a ranking for this table based on Product name total sales (Table on the right) ...
  • AntrikshSharma's avatar
    AntrikshSharma
    5 years ago

    JoseCamp  The file is attached below my signature:

    Product Rank =
    IF (
        ISINSCOPE ( Jose[Product name] ),
        VAR CurrentProduct =
            SELECTEDVALUE ( Jose[Product Name] )
        VAR TotalSellAtCurrentProduct =
            CALCULATE (
                [Total Sell],
                Jose[Product name] = CurrentProduct,
                ALLEXCEPT ( Jose, Jose[Date] ),
                ALLSELECTED ( Jose[Date] )
            )
        VAR TotalSellEachProduct =
            CALCULATETABLE (
                ADDCOLUMNS ( VALUES ( Jose[Product Name] ), "@Total Sells", [Total Sell] ),
                ALLEXCEPT ( Jose, Jose[Date] ),
                ALLSELECTED ( Jose[Date] )
            )
        VAR RankCurrentSell =
            FILTER ( TotalSellEachProduct, [@Total Sells] >= TotalSellAtCurrentProduct )
        VAR Result =
            COUNTROWS ( RankCurrentSell )
        RETURN
            Result
    )