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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
Anonymous
Not applicable

Top5 & Others -- Sorting Problem

Hi All,

i really need help on this one. I copied the measure to get Top5 & Others (i copied, it is too advance for my PBI knowledge). It works perfectly but i have a problem with the sorting. As you can see in the picture, everything is sorted by SALES (Measure) but i would need to keep "ZZ_Other" Category always at the bottom. I am using the formula below to get the Top5 & Others Measure. Where i can adjust it the keep "Others" always at the bottom while keeping everything else sorted by sales.

Thanks

Luca

 

APIwOthers Sales PY =
VAR Items =
    SELECTCOLUMNS ( ALL ( NewAPI ), "RankItem", NewAPI[API Description] )
VAR ItemsWithValue =
    ADDCOLUMNS (
        Items,
        "RankMeasure", CALCULATE ( [Sales], ALL ( XXX_API[API Description] ) )
    )
VAR ItemsWithRank =
    ADDCOLUMNS (
        ItemsWithValue,
        "Rank", RANKX ( ItemsWithValue, [Sales], [Sales], DESC, DENSE )
    )
VAR ItemsWithTop =
    ADDCOLUMNS (
        ItemsWithRank,
        "TopOrOthers", IF ( [Rank] <= 5, [RankItem], "ZZ_Other APIs" )
    )
VAR ItemsFinal =
    SELECTCOLUMNS (
        FILTER (
            ItemsWithTop,
            CONTAINSROW ( VALUES ( NewAPI[API Description] ), [TopOrOthers] )
                && CONTAINSROW ( VALUES ( XXX_API[API Description] ), [RankItem] )
        ),
        "TopN_Others", [RankItem]
    )
RETURN
    CALCULATE ( [Sales PY], TREATAS ( ItemsFinal, NewAPI[API Description] ) )

 

 

 

 

Actual ResultActual Result

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous,

You can create a custom sort table with all category values and index who used to setting 'sort by column' property. Then you can use category link to raw table and use new table category fields on the matrix to achieve custom sorting.

Custom Sorting in Power BI 
Regards,

Xiaoxin Sheng

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Anonymous,

You can create a custom sort table with all category values and index who used to setting 'sort by column' property. Then you can use category link to raw table and use new table category fields on the matrix to achieve custom sorting.

Custom Sorting in Power BI 
Regards,

Xiaoxin Sheng

ChrisMendoza
Resident Rockstar
Resident Rockstar

@Anonymous - Have you taken a look at → https://www.sqlbi.com/articles/showing-the-top-5-products-and-others-row/






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.