Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

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

  • wdx223_Daniel's avatar
    wdx223_Daniel
    Icon for Community Champion rankCommunity Champion

    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.