0
0
Power BIbi_tool~20 mins

TOPN function in Power BI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
TOPN Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
dax_lod_result
intermediate
2:00remaining
Understanding TOPN with a single column
Given a Sales table with columns Product and SalesAmount, what does the following DAX expression return?

TOPN(3, Sales, Sales[SalesAmount], DESC)

Choose the correct description of the output.
Power BI
TOPN(3, Sales, Sales[SalesAmount], DESC)
AReturns the top 3 rows with the highest SalesAmount values from the Sales table.
BReturns all rows where SalesAmount is greater than 3.
CReturns the bottom 3 rows with the lowest SalesAmount values from the Sales table.
DReturns 3 random rows from the Sales table.
Attempts:
2 left
💡 Hint
TOPN returns a specified number of rows ordered by a column.
visualization
intermediate
2:00remaining
Visualizing TOPN results in a report
You want to create a bar chart in Power BI that shows the top 5 products by total sales. Which DAX measure would correctly filter the products to show only the top 5 in the chart?
ATop5Products = TOPN(5, Sales, Sales[SalesAmount], ASC)
BTop5Products = FILTER(VALUES(Sales[Product]), Sales[SalesAmount] > 5)
CTop5Products = CALCULATE(SUM(Sales[SalesAmount]), TOPN(5, Sales, Sales[SalesAmount], DESC))
DTop5Products = TOPN(5, VALUES(Sales[Product]), CALCULATE(SUM(Sales[SalesAmount])), DESC)
Attempts:
2 left
💡 Hint
Use TOPN with VALUES to get distinct products ordered by total sales.
data_modeling
advanced
2:00remaining
Using TOPN with multiple sort columns
You have a Sales table with columns Product, Region, and SalesAmount. You want to get the top 3 sales rows ordered first by Region ascending, then by SalesAmount descending. Which DAX expression achieves this?
ATOPN(3, Sales, Sales[SalesAmount], DESC, Sales[Region], ASC)
BTOPN(3, Sales, Sales[Region], ASC, Sales[SalesAmount], DESC)
CTOPN(3, Sales, Sales[Region], DESC, Sales[SalesAmount], ASC)
DTOPN(3, Sales, Sales[SalesAmount], ASC, Sales[Region], DESC)
Attempts:
2 left
💡 Hint
The order of columns and their sort directions matter in TOPN.
🔧 Formula Fix
advanced
2:00remaining
Identify the error in this TOPN usage
What error will the following DAX expression cause?

TOPN(5, Sales, Sales[SalesAmount])

Assuming Sales[SalesAmount] is numeric.
Power BI
TOPN(5, Sales, Sales[SalesAmount])
ASyntax error because the sort order (ASC or DESC) is missing.
BReturns bottom 5 rows instead of top 5.
CRuntime error because SalesAmount is numeric and cannot be sorted.
DNo error; it returns top 5 rows sorted ascending by SalesAmount by default.
Attempts:
2 left
💡 Hint
TOPN requires explicit sort order for each sort column.
🧠 Conceptual
expert
3:00remaining
Scenario: Combining TOPN with CALCULATE and FILTER
You want to create a measure that calculates total sales for the top 3 products by sales amount, but only for the current year. Which DAX expression correctly achieves this?
ACALCULATE(SUM(Sales[SalesAmount]), FILTER(ALL(Sales), Sales[Product] IN TOPN(3, ALL(Sales[Product]), CALCULATE(SUM(Sales[SalesAmount])), DESC) && YEAR(Sales[Date]) = YEAR(TODAY())))
BCALCULATE(SUM(Sales[SalesAmount]), TOPN(3, ALL(Sales[Product]), CALCULATE(SUM(Sales[SalesAmount])), DESC), YEAR(Sales[Date]) = YEAR(TODAY()))
CCALCULATE(SUM(Sales[SalesAmount]), FILTER(ALL(Sales[Product]), Sales[Product] IN TOPN(3, ALL(Sales[Product]), CALCULATE(SUM(Sales[SalesAmount])), DESC) && YEAR(Sales[Date]) = YEAR(TODAY())))
DCALCULATE(SUM(Sales[SalesAmount]), FILTER(ALL(Sales[Product]), Sales[Product] IN TOPN(3, ALL(Sales[Product]), CALCULATE(SUM(Sales[SalesAmount])), DESC)), YEAR(Sales[Date]) = YEAR(TODAY()))
Attempts:
2 left
💡 Hint
Use FILTER with ALL on Product and include the year filter inside FILTER.