Forum Discussion

Touliloop's avatar
Touliloop
Helper I
10 months ago
Solved

Dynamic ranking use RANKX() show duplicates

I have a dataset "table" as follows:

Countrydatetimeeventchannelprice
UK2025-01-015BBC200
US2025-01-033ABC198

 

Purpose is to give all the channel a ranking, based on their #event_per_hour and € Cost per event . To do that I bulild the measures below and by rank the #event_per_hour desc and €cost_per_event asc, they receive two rankings, then I sum up the two rankings and got a score, at the end I sort the channel by the score asc to have the final ranking "§TOTAL RANKING".

 

Until sum the two rankings to get the score it works fine. But when I use the final measure § TOTAL RANKING, the weird thing happens, the total ranking doesn't sstart from 1 and has duplicates, see these examples:

Scorecurrent Total rankingexpected Total ranking
2ExcludedExcluded
751
7ExcludedExcluded
751
751
1162
1463

 

Can someone tell me what causes this problem and how to fix it? The visual is being filtered by the column "Country", each time one single selection of the slice "Country".

Measures:

  • # Channel_count = CALCULATE(COUNT(table[channel]))
  • # Sum_event = SUM(table[event)]
  • # event_per_hour= DIVIDE([# Sum_event], [# Channel_count],0)#
  • € Total cost = CALCULATE(SUM(table[price]))
  • € Cost per event = (DIVIDE([€ Total cost],[# Sum event],0))
  • Test_ranking_event =
         VAR FilteredTable =
         FILTER(
         ALLSELECTED(table [channel]),
         NOT(ISBLANK([# Channel_count])) // Ensures only valid rows are ranked
)
         RETURN
         IF([# Channel_count] <> BLANK(), CALCULATE(RANKX(FilteredTable, [# event_per_hour],, DESC)))
 
  • Test_rank_cost =
         VAR FilteredTable =
         FILTER(
         ALLSELECTED(table[channel]),
         NOT(ISBLANK([# Channel_count])) // Ensures only valid rows are ranked
)
       RETURN
       IF([# Channel_count] <> BLANK(), CALCULATE(RANKX(FilteredTable, [€ Cost per event ],, ASC)))
 
  • Score = table[Test_rank_cost] + table[Test_ranking_event]
  • § TOTAL RANKING=

    VAR FilteredTable =
    FILTER(
    ALLSELECTED(table[channel]),
    [€ Total cost] > 0 // Exclude zero-cost rows
    )
    RETURN
    IF([# Channel_count_2025] <> BLANK(), CALCULATE(IF(
    [€ Total cost] = 0,
    "EXCLUDED",
    RANKX(FilteredTable, [Score],, ASC)
    )))

           

  • Touliloop's avatar
    Touliloop
    10 months ago

    Hi, thanks for your hint, I would like to close this querstion, I created a new one with sample data and better format.

5 Replies