Forum Discussion
KongZY
2 years agoNew Member
Need help with DAX code to show top 10 categories while labelling the other categories as "Others"
Hi, I am looking to write a DAX measure to find the vendors with the top 5 sales, and to label the other vendors as "Others" as I want to avoid showing too many different vendor names when I build th...
ERD
Community Champion
2 years agoHi KongZY ,
To achieve the result you need to:
1. Create a separate table with all vendors + 'Others'. One of the ways is to do it in Power Query
let
Source = t,
#"Removed Other Columns" = Table.SelectColumns(Source,{"Vendor Name"}),
#"Removed Duplicates" = Table.Distinct(#"Removed Other Columns"),
Custom1 = Table.InsertRows(#"Removed Duplicates", 0, {[Vendor Name="Others"]})
in
Custom1
2. Create measures:
total value = SUM(t[Value])vendor_rank = RANKX ( ALL ( vendors[Vendor Name] ), [total value],, DESC )custom_value =
VAR others = FILTER ( ALL ( vendors[Vendor Name] ), [vendor_rank] > 5 )
VAR others_value = SUMX ( others, [total value] )
RETURN
IF (
[vendor_rank] <= 5,
[total value],
IF ( SELECTEDVALUE ( vendors[Vendor Name] ) = "Others", others_value )
)