Forum Discussion
TOP N by few columns
- 1 year ago
Hello Ania26
You can use the following DAX formula to create a calculated column in the table
Rank - Calculated = VAR _currentMarket = 'Table'[Market] VAR _currentYear = 'Table'[Year] RETURN RANKX ( FILTER ( 'Table', 'Table'[Market] = _currentMarket && 'Table'[Year] = _currentYear ), 'Table'[Sales], , DESC, DENSE )Here is the screenshot of the results table for your reference:
Assuming that the "Rank" column provided in the data table the expected ranking, it is evident that for the "France" market in the year "2019", "Coca-Cola" has higher sales than "Omo". Therefore, Omo should be ranked 2 instead 1, as the ranking should be in descending order of sales. This appears to be a human error, but please confirm if otherwise.
I am also attaching the Power BI file for your refernce.
Best Regards,
Udit
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudo 👍
🚀 Let's Connect: LinkedIn || YouTube || Medium || GitHub
✨ Visit My Linktree: LinkTreeProud to be a Super User
The error is because you are trying to add a column instead of a measure.
If you need a column, you might want to try something like:
RANK(
DENSE,
ALL( tbl3[Year], tbl3[Sales], tbl3[Market] ),
ORDERBY(tbl3[Year], ASC, tbl3[Sales], DESC),
PARTITIONBY(tbl3[Year], tbl3[Market])
)