Forum Discussion
Creating "Others" category for a chart
Hi,
I have about 20 Brands ("Brand2" in my data) and am trying to put the top 5 by volume in a chart then the "Others" in a grouping.
I have created 3 lines of DAX :
Hi Lucas_Radebe
if you want to be able to use the rank measure in a legend, you must materialize the result using a table that contains the rank numbers.
Top N Sales with Other = VAR SummarizedSales = SUMMARIZECOLUMNS ( 'Product'[Model], "@rank", [Product Model Rank By Sales], "@sales", [Sales] ) VAR CategorizedSales = ADDCOLUMNS ( SummarizedSales, "@New Model", IF ( [@rank] <= [Parameter Value], [Model], "Other" ) ) VAR FilteredSales = FILTER ( CategorizedSales, [@New Model] IN VALUES ( 'Models with Other'[Model] ) ) RETURN SUMX ( FilteredSales, [@sales] )The TopN number in the above measure is parameterized but can be replaced with an actual number.
Please see the attached pbix.
4 Replies
- ryan_mayu
Super User
you can try this, if this does not work, pls provide some sample data and expected output.
Brand Grouping =
VAR TopBrands =
TOPN(
5,
SUMMARIZE('C2 Data', 'C2 Data'[Brand2], "TotalVol", SUM('C2 Data'[Volume])),
[TotalVol]
)
RETURN
IF(
'C2 Data'[Brand2] IN TopBrands,
'C2 Data'[Brand2],
"Others"
) - Ashish_Mathur
Super User
Hi,
I have solved a similar question in the attahed PBI file.
- Shahid12523
Community Champion
TopN Brand Group =
VAR BrandRank = RANKX(ALL('C2 Data'[Brand2]), CALCULATE(SUM('C2 Data'[Volume])), , DESC, Skip)
RETURN IF(BrandRank <= 5, 'C2 Data'[Brand2], "Others") - danextian
Super User
Hi Lucas_Radebe
if you want to be able to use the rank measure in a legend, you must materialize the result using a table that contains the rank numbers.
Top N Sales with Other = VAR SummarizedSales = SUMMARIZECOLUMNS ( 'Product'[Model], "@rank", [Product Model Rank By Sales], "@sales", [Sales] ) VAR CategorizedSales = ADDCOLUMNS ( SummarizedSales, "@New Model", IF ( [@rank] <= [Parameter Value], [Model], "Other" ) ) VAR FilteredSales = FILTER ( CategorizedSales, [@New Model] IN VALUES ( 'Models with Other'[Model] ) ) RETURN SUMX ( FilteredSales, [@sales] )The TopN number in the above measure is parameterized but can be replaced with an actual number.
Please see the attached pbix.