← DAX CasesRunning totals and rankingsCase 3 of 8
A customer’s rank within its city, by cars bought
Where does each customer stand among the customers of its city, by number of cars bought, written as “2 of 3”?
Row followedKumora
Our strategy
The task is to write, for each customer, its place within its city, in the form “2 of 3.” That takes a rank and a group size, both computed over the customers of the same city. The chosen approach starts by building a table of the city’s customers, which then feeds both numbers.
Click a step, and the formula lines that carry it out light up on the board.
Another way to get there
You could do without the city variable and write CALCULATETABLE( VALUES( Customers[Name] ), ALL( Customers[Name] ), VALUES( Customers[City] ) ). The VALUES( Customers[City] ) is read before the filter changes, and brings in the customer’s city. Tested on the model, this rank is the same for all seven customers. We preferred to name the city, which makes the condition readable at a glance.