18.1Ranking with RANKX

In Excel
ExcelRANK.EQ
Match

Who is your top customer? RANKX ranks the values of a table by a measure. A single argument makes all the difference, the list of items to rank.

18.1.1The syntax of RANKX

RANKX calculates an expression, often a measure, for each row of a table, then returns the rank of the current row.

RANKX( <table>, <expression>, [<value>], [<order>], [<ties>] )

It first expects the table of the items to rank, then the expression calculated for each of them, often a measure. The last three arguments are optional. The default order is DESC, and the largest figure gets rank 1. In this lesson, we write it out so that you can see it. With ASC, the smallest figure comes first. The third argument, the value, stays empty in this lesson.

Rank = RANKX( ALL( Customers[Name] ), [Revenue], , DESC )
Power BI accepts this DAX foryes, Measureyes, Calculated columnno, Calculated tableno, Virtual table
In plain words

“I want the rank of each customer, ordering all the customers from the highest revenue to the lowest, and reading the place of each one.”

Table visual, The “Rank” measure by customer
NameRank
Orvane1
Kumora2
Ribelia3
Movara3
Northel5
Talvio6
Sam Lee7
Total1

This is a reproduction of the Power BI interface for teaching purposes. It differs from the real interface.

Ribelia and Movara both reach 250,000. They share rank 3, and rank 4 is skipped.

Tip

The “Total” row shows 1. On this row, RANKX calculates the revenue of the row, 1,700,000, then compares it with that of the seven customers that ALL provides. It beats them all, hence rank 1. You will often hide this rank with ISINSCOPE, covered with the essential functions.

Practice

Each exercise is solved with the function you just discovered. Two exercises per function, a direct use and a combined use, from easiest to hardest, on data other than the course data. Pick the right formula out of five.

  1. Direct useMeasureDifficulty

    A cycling championship already has a “Points” measure, the sum of the “Points” column of the “Results” table. In a table by rider, write the “Ranking” measure, which orders all the riders from the most points to the fewest.

    Results
    RiderPoints
    Lina45
    Marc60
    Noé52

    Which formula should you write for “Ranking”?

  2. Combined useMeasureDifficulty

    A swimming competition already has a “Time” measure, which returns a swimmer’s time, in seconds. The best swimmer has the shortest time. In a table by swimmer, with the Races[Swimmer] column, write the “Place” measure, which gives first place to the shortest time.

    Races
    SwimmerTime
    Ana62
    Ben58
    Cléo65

The rest of this lesson is part of izyDAX Pro

You have just read the first section. The next 2, their animations, the exercises and the summary are waiting for you with izyDAX Pro, in a single payment.