Forum Discussion

RasmusN532's avatar
RasmusN532
Helper I
2 years ago
Solved

Top 10 RANKX with two columns and IF ?

Hi all, Fairly new to power BI and have stumbled upon a issue I cant seem to find any solution on.   So firstly, I have a dataset example as follows:   Customer Hierarchy 1 Customer Hierarch...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi RasmusN532 ,

     

    According to your description, I modified the formula. the Top10Customers parameter returns the table that satisfies the top10 condition, and the results are based on this table in the later conditional judgment.

    Top10Customers1 = 
        TOPN (
            10,
            SUMMARIZE (
                'YourTable',
                'YourTable'[Customer Hierarchy 1],
                "TotalSales", CALCULATE ( MAX(YourTable[Net Sales]) )
            ),
            [TotalSales], DESC
        )


    You can refine this formula and apply it to the complete data model.

    Rank Customer = 
    VAR Top10Customers =
        TOPN (
            10,
            SUMMARIZE (
                'YourTable',
                'YourTable'[Customer Hierarchy 1],
                "TotalSales", CALCULATE ( MAX(YourTable[Net Sales]) )
            ),
            [TotalSales], DESC
        )
    RETURN
        IF (
            ISINSCOPE ( 'YourTable'[Customer Hierarchy 1] ),
            RANKX ( Top10Customers, [TotalSales] ),
            IF (
                ISINSCOPE ( 'YourTable'[Customer Hierarchy 2] ),
                RANKX (
                    FILTER (
                        Top10Customers,
                        'YourTable'[Customer Hierarchy 1] = BLANK ()
                    ),
                    [TotalSales]
                )
            )
        )

     

    Best Regards,
    Adamk Kong

     

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