Forum Discussion

Chateauunoirr's avatar
Chateauunoirr
Advocate I
1 year ago
Solved

Help Needed: Understanding Differences in RANKX Measures in Power BI

Hello everyone,   I am currently working on Power BI and have created two measures to rank a table of series. Here are the measures I used: Rank1 = RANKX(ALL(Series), SUM(Series[Viewers (m)])) R...
  • bhanu_gautam's avatar
    1 year ago

    Chateauunoirr , For 1 st one

    SUM(Series[Viewers (m)]) is evaluated in the current row context of the Series table.

    Since RANKX iterates over the table specified in the first argument (ALL(Series)), it evaluates SUM(Series[Viewers (m)]) in the context of each row. However, without a CALCULATE function, the SUM function does not properly aggregate the values across the entire table, leading to incorrect results where each row context might just return the value of the current row, resulting in all ranks being 1.

     

    In second CALCULATE(SUM(Series[Viewers (m)])) changes the context in which the SUM function is evaluated. CALCULATE forces the SUM to be evaluated in the context of the entire table (due to ALL(Series)), thus correctly aggregating the Viewers (m) values across all rows in the Series table. This allows RANKX to correctly rank the series based on the total viewers.