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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Ar_Sh
Advocate II
Advocate II

DAX

Trying to build a customer performance view where a slicer controls the Top N value. The matrix should display the Top N customers by sales and then show a single Others row that groups all remaining customers. Total Sales and a What If parameter for selecting N already exist. Guidance is needed on writing DAX that returns the Top N customers correctly, calculates Others as the remaining sales, and keeps the matrix total showing the full combined amount without breaking the visual layout.

2 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.
I tried to create a sample pbix file like below.

 

Jihwan_Kim_1-1765026860694.png

 

 

Jihwan_Kim_0-1765026815230.png

 

Sales: = 
SUM(sales[sales])

 

 

Top N sales: = 
VAR _topN = [prm_top_N Value]
VAR _topNtable =
    WINDOW (
        1,
        ABS,
        _topN,
        ABS,
        ALL ( Customer[customer] ),
        ORDERBY ( [Sales:], DESC )
    )
VAR _topNsales =
    CALCULATE ( [Sales:], KEEPFILTERS ( _topNtable ) )
RETURN
    SWITCH (
        TRUE (),
        SELECTEDVALUE ( Customer[customer] ) = "Others",
            CALCULATE ( [Sales:], REMOVEFILTERS ( Customer[customer] ) )
                - CALCULATE ( [Sales:], _topNtable ),
        HASONEVALUE ( Customer[customer] ), _topNsales,
        [Sales:]
    )

 


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.

View solution in original post

Shubham_rai955
Memorable Member
Memorable Member

 

You can handle Top N plus an Others row using two measures and a display logic measure.

Top N Customers

 

 
TopN Customers = VAR N = SELECTEDVALUE('TopN Parameter'[TopN Value], 5) RETURN IF( RANKX( ALL('Customer'[Customer Name]), [Total Sales], , DESC ) <= N, [Total Sales] )

Others Sales

 

 
Others Sales = VAR N = SELECTEDVALUE('TopN Parameter'[TopN Value], 5) VAR TopNTable = TOPN(N, ALL('Customer'[Customer Name]), [Total Sales], DESC) VAR TotalAll = CALCULATE([Total Sales], ALL('Customer')) VAR TotalTopN = CALCULATE([Total Sales], TopNTable) RETURN TotalAll - TotalTopN

Label Measure

 

 
Customer Label = VAR N = SELECTEDVALUE('TopN Parameter'[TopN Value], 5) VAR IsTopN = RANKX( ALL('Customer'[Customer Name]), [Total Sales], , DESC ) <= N RETURN IF(IsTopN, SELECTEDVALUE('Customer'[Customer Name]), "Others")

Use Customer Label in the matrix rows
Use TopN Customers as the value
Add Others Sales as a second value

Matrix total will show full sales, Top N will show individually, and Others will neatly group the rest.

View solution in original post

2 REPLIES 2
Shubham_rai955
Memorable Member
Memorable Member

 

You can handle Top N plus an Others row using two measures and a display logic measure.

Top N Customers

 

 
TopN Customers = VAR N = SELECTEDVALUE('TopN Parameter'[TopN Value], 5) RETURN IF( RANKX( ALL('Customer'[Customer Name]), [Total Sales], , DESC ) <= N, [Total Sales] )

Others Sales

 

 
Others Sales = VAR N = SELECTEDVALUE('TopN Parameter'[TopN Value], 5) VAR TopNTable = TOPN(N, ALL('Customer'[Customer Name]), [Total Sales], DESC) VAR TotalAll = CALCULATE([Total Sales], ALL('Customer')) VAR TotalTopN = CALCULATE([Total Sales], TopNTable) RETURN TotalAll - TotalTopN

Label Measure

 

 
Customer Label = VAR N = SELECTEDVALUE('TopN Parameter'[TopN Value], 5) VAR IsTopN = RANKX( ALL('Customer'[Customer Name]), [Total Sales], , DESC ) <= N RETURN IF(IsTopN, SELECTEDVALUE('Customer'[Customer Name]), "Others")

Use Customer Label in the matrix rows
Use TopN Customers as the value
Add Others Sales as a second value

Matrix total will show full sales, Top N will show individually, and Others will neatly group the rest.

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.
I tried to create a sample pbix file like below.

 

Jihwan_Kim_1-1765026860694.png

 

 

Jihwan_Kim_0-1765026815230.png

 

Sales: = 
SUM(sales[sales])

 

 

Top N sales: = 
VAR _topN = [prm_top_N Value]
VAR _topNtable =
    WINDOW (
        1,
        ABS,
        _topN,
        ABS,
        ALL ( Customer[customer] ),
        ORDERBY ( [Sales:], DESC )
    )
VAR _topNsales =
    CALCULATE ( [Sales:], KEEPFILTERS ( _topNtable ) )
RETURN
    SWITCH (
        TRUE (),
        SELECTEDVALUE ( Customer[customer] ) = "Others",
            CALCULATE ( [Sales:], REMOVEFILTERS ( Customer[customer] ) )
                - CALCULATE ( [Sales:], _topNtable ),
        HASONEVALUE ( Customer[customer] ), _topNsales,
        [Sales:]
    )

 


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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.