Forum Discussion

camilocorralesg's avatar
camilocorralesg
Advocate I
3 years ago
Solved

Problem with TOP N results

Hi everybody, I'm experiencing some trouble with my DAX measure to calculate dynamic TOP N values based on agent performance. First, my Income measure is = SUM(Income) Then, I calculated this DAX m...
  • Greg_Deckler's avatar
    3 years ago

    camilocorralesg Well, you aren't accounting for the Year context so your RANKX in 2020 is likely returning different top agents than across all years. So, if a particular agent did really well in 2020 and better than your top performers overall, this would account for the discrepency. You could solve this by doing something like:

    Measure =
      VAR __Table = SUMMARIZE(ALL('fct_hotel_revenue),[agent],"__Rank",[RANK INCOME])
      VAR __Agents = SELECTCOLUMNS(FILTER(__Table,[__Rank]<=6),"agent",[agent])
      VAR __Table1 = FILTER('fct_hotel_revenue',[agent] IN __Agents)
    RETURN
      SUMX(__Table1,[Income])

    The idea here is to first get your top agents (__Agents) across all years or all whatever you have in your visual. You then filter your fact table within the context of the visual (this case years) so that you only return those agents in each of the years and then just do an X aggregation across that table.