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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
fa82
Regular Visitor

Top N + Others using sum of columns

Hi Everyone,

 

I'm trying to get a dynamic top N + Others rows in matrix using a sum of the columns

My table has: Customer, Category, Value

fa82_0-1640847871774.png

 

And matrix looks like this:

fa82_1-1640847907228.png

 

Is there a way to display the top 5 customers + 'others';  Top 5 being determined by a sum of the values in all categories A-D for each customer?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @fa82 ,

 

If you want to add Category to Matrix visual as well, please follow these steps.

 

1. Create a rank measure:

Rank = RANKX(ALL('Table'), CALCULATE(SUM('Table'[Value]),ALLEXCEPT('Table','Table'[Customers])),,DESC,Dense)

2. Add a new table, do not need to build relationships.

Table 2 = 
var _t1= UNION( VALUES('Table'[Customers]),ROW("Customers","Others"))
var _t2=VALUES('Table'[Category])
return CROSSJOIN(_t1,_t2)

Eyelyn9_0-1641193902306.png

 

3. Create a measure:

Measure =
VAR _t =
    SUMMARIZE ( FILTER ( 'Table', [Rank] <= 5 ), [Customers] )
VAR _value =
    SWITCH (
        MAX ( 'Table 2'[Customers] ),
        "Others",
            CALCULATE (
                SUM ( 'Table'[Value] ),
                FILTER ( 'Table', [Rank] > 5 && [Category] = MAX ( 'Table 2'[Category] ) )
            ),
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER (
                'Table',
                [Customers] = MAX ( 'Table 2'[Customers] )
                    && [Category] = MAX ( 'Table 2'[Category] )
            )
        )
    )
VAR _sum =
    IF (
        MAX ( 'Table 2'[Customers] ) = "Others",
        CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( 'Table', [Rank] > 5 ) ),
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER ( 'Table', [Customers] = MAX ( 'Table 2'[Customers] ) )
        )
    )
RETURN
    IF (
        MAX ( 'Table 2'[Customers] )
            IN _t
                || MAX ( 'Table 2'[Customers] ) = "Others",
        IF ( HASONEVALUE ( 'Table 2'[Category] ), _value, _sum ),
        BLANK ()
    )

Final output:

Eyelyn9_1-1641194496481.png

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @fa82 ,

 

If you want to add Category to Matrix visual as well, please follow these steps.

 

1. Create a rank measure:

Rank = RANKX(ALL('Table'), CALCULATE(SUM('Table'[Value]),ALLEXCEPT('Table','Table'[Customers])),,DESC,Dense)

2. Add a new table, do not need to build relationships.

Table 2 = 
var _t1= UNION( VALUES('Table'[Customers]),ROW("Customers","Others"))
var _t2=VALUES('Table'[Category])
return CROSSJOIN(_t1,_t2)

Eyelyn9_0-1641193902306.png

 

3. Create a measure:

Measure =
VAR _t =
    SUMMARIZE ( FILTER ( 'Table', [Rank] <= 5 ), [Customers] )
VAR _value =
    SWITCH (
        MAX ( 'Table 2'[Customers] ),
        "Others",
            CALCULATE (
                SUM ( 'Table'[Value] ),
                FILTER ( 'Table', [Rank] > 5 && [Category] = MAX ( 'Table 2'[Category] ) )
            ),
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER (
                'Table',
                [Customers] = MAX ( 'Table 2'[Customers] )
                    && [Category] = MAX ( 'Table 2'[Category] )
            )
        )
    )
VAR _sum =
    IF (
        MAX ( 'Table 2'[Customers] ) = "Others",
        CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( 'Table', [Rank] > 5 ) ),
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER ( 'Table', [Customers] = MAX ( 'Table 2'[Customers] ) )
        )
    )
RETURN
    IF (
        MAX ( 'Table 2'[Customers] )
            IN _t
                || MAX ( 'Table 2'[Customers] ) = "Others",
        IF ( HASONEVALUE ( 'Table 2'[Category] ), _value, _sum ),
        BLANK ()
    )

Final output:

Eyelyn9_1-1641194496481.png

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Your solution worked perfectly, thank you!

Bonus question: Is there a way to ensure the 'others' row appears last? 

PC2790
Community Champion
Community Champion

I had a similar problem and I found this video quite simple to use.

See if it covers your requirement

 

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

All measures are in the attached pbix file.

 

 

Picture1.png


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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