The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
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.
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.
@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
User | Count |
---|---|
14 | |
12 | |
7 | |
6 | |
5 |
User | Count |
---|---|
28 | |
18 | |
13 | |
7 | |
5 |