Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Anonymous
Not applicable

TOPN in Microsoft Docs wrong documentation ERROR

I understand that TOPN is a table function which takes the following parameters:

- how many rows you want to show

- which table name

- what do you want to sort it by

 

In the documentation: https://docs.microsoft.com/en-gb/learn/modules/perform-analytics-power-bi/2-statistical-summary

 

Microsoft showed an example of using TOPN on the "Top 10 products by TOTAL SALE" and this was the formula given:

 

Top 10 Products = SUMX ( TOPN ( 10, Product, Product[Product Name], ASC ), [Total Sales] )

 

I am interprething this as sum the top 10 products BASED ON THE PRODUCT NAME rather than total sales. Am I missing something out here? Shouldn't the 3rd paramter be total sales rather than Product[Product Name]?

 

the parameters in the example of TOPN is:

- 10

- Product table

- Sort by Product Name (Isin't this wrong??)

 

Would appreciate any guidance on this.

 

2 REPLIES 2
wdx223_Daniel
Super User
Super User

TOPN is a iterator, it generates a row context based on the second parameter. if the sort by field,ie the third parameter, is one column of the second parameter, then it will reference the field of conresponding row. if you set a field which not belongs to the second parameter, then will get a error, then you need to use a expression of aggregation function or a measure. on this point, you must be careful of context transactions. a measure or a expression using calculate function will automatically transacts all current row context into filter context.  

amitchandak
Super User
Super User

@Anonymous , If you need top 10 based on sales it should be like

TOPN(10,all(Product[Product Name]),[Sales],DESC)

 

Please refer to my video if that can help https://www.youtube.com/watch?v=QIVEFp-QiOk

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.