Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
KongZY
New 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 the visual. This is my thought process:

  1. Sum up the sales for each vendor
  2. Rank the vendors according to their total sales
  3. Label the vendors who rank 6 or higher as "Others"

With this thought process, I write the following DAX expression but it did not work:

VendorRanked = IF(
    RANKX(ALL('PurchaseOrders'[Vendor Name]), SUM('PurchaseOrders'[Value])) <= 5,
    VALUES('PurchaseOrders'[Vendor Name]),
    "Others"
)
Not sure what I am doing wrong here, can I have some advice?

My base PurchaseOrder table looks something like this:
Vendor NameOrder No.Value
Vendor 1110
Vendor 1215
Vendor 2

3

15
Vendor 2415
Vendor 3525
Vendor 465
Vendor 5730
Vendor 6830
Vendor 7910


And I am looking to get something like this:

Output Column/MeasureTotal Value
Vendor 125
Vendor 230
Vendor 325
Vendor 530
Vendor 630
Others15

 

Appreciate if you can provide me with some advice or guidance.

Edit: Link to sample file - https://we.tl/t-NCWML5aA4X 

5 REPLIES 5
ERD
Community Champion
Community Champion

Hi @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 )
    )

ERD_0-1699949062283.png

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

mh2587
Super User
Super User

VendorRanked = // Try this one might help you
VAR VendorSales = 
    SUMMARIZE(
        'PurchaseOrders',
        'PurchaseOrders'[Vendor Name],
        "TotalSales", SUM('PurchaseOrders'[Value])
    )
RETURN
    IF(
        RANKX(VendorSales, [TotalSales], , DESC) <= 5,
        'PurchaseOrders'[Vendor Name],
        "Others"
    )

Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



Hi Muhammad, thank you for your response. Can I check with you is your solution meant to be a measure or a column?

I have the following issue when I run it as a measure:

KongZY_0-1699876386735.png


And this issue when I run it as a calculated column:

KongZY_1-1699876433594.png

 

 

//Try this one
VendorRanked = 
VAR VendorSales = 
    SUMMARIZE(
        'PurchaseOrders',
        'PurchaseOrders'[Vendor Name],
        "TotalSales", SUM('PurchaseOrders'[Value])
    )
VAR CurrentVendor = VALUES('PurchaseOrders'[Vendor Name])
RETURN
    IF(
        RANKX(VendorSales, [TotalSales], , DESC) <= 5,
        CurrentVendor,
        "Others"
    )

Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



Hi Muhammad, thank you for your help. I played around a bit and managed to get it to work using

FIRSTNONBLANK('PurchaseOrders'[Vendor Name], [Vendor Name])

inside the RETURN function. I suspect is because the measure would take a column as a return value.

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors