Forum Discussion
TOP N with TOP N
Do you maybe know how in each year, for each Market show top N Companies and for those companies show top n Color?
| Market | Year | Company | Color | Sales |
| France | 2019 | Omo | White | 1 |
| France | 2020 | CocaCola | Brown | 2 |
| France | 2019 | CocaCola | Brown | 3 |
| Poland | 2019 | CocaCola | Light Brown | 1 |
| Poland | 2020 | CocaCola | Brown | 3 |
| Poland | 2021 | Omo | Pink | 4 |
| Poland | 2021 | Omo | White | 4 |
| Poland | 2021 | CocaCola | Brown | 3 |
I would like to display it in the stacked column chart. Show TOP N Companies and the rest in "OTHERS" column and for each company top N Color and the rest in "Others" column.
- Anonymous1 year ago
Hi Ania26
Try this:
Create calculated columns.
Company Group = VAR N = 1 // Custom top N ranking. VAR _rank = RANKX( FILTER( ALL('Table'), 'Table'[Market] = EARLIER('Table'[Market]) && 'Table'[Year] = EARLIER('Table'[Year]) ), 'Table'[Sales], , DESC, Dense ) RETURN IF( _rank <= N, 'Table'[Company], "Others" )Color Group = VAR N = 1 // Custom top N ranking. VAR _rank = RANKX( FILTER( ALL('Table'), 'Table'[Market] = EARLIER('Table'[Market]) && 'Table'[Company] = EARLIER('Table'[Company]) && 'Table'[Year] = EARLIER('Table'[Year]) ), 'Table'[Sales], , DESC, Dense ) RETURN IF( _rank <= N, 'Table'[Color], "Others" )Create a stacked column chart.
Here is the result.
Regards,
Nono Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
4 Replies
- Rupak_bi
Super User
Hi,
Based on the sample data, please illustrate the look of the desired output for better undershanding.
- Akash_Varuna
Super User
Hi Ania26 Could You try this please
Rank Companies:
CompanyRank = RANKX(ALL('Table'[Company]), SUM('Table'[Sales]), , DESC)Group Companies:
CompanyCategory = IF([CompanyRank] <= N, 'Table'[Company], "Others")Rank Colors:
ColorRank = RANKX(ALL('Table'[Color]), SUM('Table'[Sales]), , DESC)Group Colors:
ColorCategory = IF([ColorRank] <= N, 'Table'[Color], "Others")Create Chart:
- Axis: Year, Market.
- Values: SUM(SALES).
If this post helped please do give a kudos and accept this as a solution
Thanks In Advance - quantumudit
Super User
Hello Ania26
Could you please specify the number for "N" when you to Top-N results? Additionally, will the top companies be determined based on the ranking we have conducted?
Thanks,Udit
- AnonymousNot applicable
Hi Ania26
Try this:
Create calculated columns.
Company Group = VAR N = 1 // Custom top N ranking. VAR _rank = RANKX( FILTER( ALL('Table'), 'Table'[Market] = EARLIER('Table'[Market]) && 'Table'[Year] = EARLIER('Table'[Year]) ), 'Table'[Sales], , DESC, Dense ) RETURN IF( _rank <= N, 'Table'[Company], "Others" )Color Group = VAR N = 1 // Custom top N ranking. VAR _rank = RANKX( FILTER( ALL('Table'), 'Table'[Market] = EARLIER('Table'[Market]) && 'Table'[Company] = EARLIER('Table'[Company]) && 'Table'[Year] = EARLIER('Table'[Year]) ), 'Table'[Sales], , DESC, Dense ) RETURN IF( _rank <= N, 'Table'[Color], "Others" )Create a stacked column chart.
Here is the result.
Regards,
Nono Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.