You have 2 minutes to solve this Power BI problem.
You have a Sales table with the following columns:
Product
Sales
Create a DAX measure to rank products based on total sales, with the highest-selling product ranked as 1.
๐ ๐ฒ: Challenge accepted! ๐ช
Product Rank =
RANKX(
ALL(Sales[Product]),
[Total Sales],
,
DESC,
DENSE
)
๐ก Explanation:
โข RANKX() assigns a rank to each product based on its total sales.
โข ALL(Sales) removes the product filter so all products are included in the ranking.
โข [Total Sales] is the expression used for ranking.
โข DESC ranks the highest sales as Rank 1.
โข DENSE ensures there are no gaps in ranking when products have the same sales.[Product]
This challenge tests your understanding of: โ RANKX()
โ ALL()
โ Ranking in DAX
โ Filter Context
๐ฏ Expected Output Example
Product: Laptop | Sales: 75,000 | Rank: 1
Product: Mobile | Sales: 68,000 | Rank: 2
Product: Monitor | Sales: 52,000 | Rank: 3
Product: Keyboard | Sales: 52,000 | Rank: 3
Product: Mouse | Sales: 40,000 | Rank: 4
๐ Bonus (Rank Within Selected Filters)
Product Rank =
RANKX(
ALLSELECTED(Sales[Product]),
[Total Sales],
,
DESC,
DENSE
)
Using ALLSELECTED() makes the ranking dynamic by considering the products visible after slicers and filters are applied.
๐ Tip for Power BI Job Seekers:
RANKX() is one of the most frequently asked DAX functions. Be comfortable using it for:
โข Top N Products
โข Customer Ranking
โข Employee Performance Ranking
โข Regional Sales Ranking
โข Dynamic Leaderboards
React with โค๏ธ for more Power BI interview challenges!