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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Show top n and "others" values

Hello everyone, 

I want to create a measure that returns the top 5 values ranked by [measure] and the sum of the others in the same graphic.

 

My table columns are (granularity order ID):

 - order ID

 - sales

 - quantity

 - product name

and more metrics like order date, state, etc

The issue is that the [measure] I want to call to rank is switching metrics between sales and quantity, so it is hard to work on a calculated column; 

moreover I would like the result to be dynamically filtered by other dim.

 

 

2 ACCEPTED SOLUTIONS

Hi @Anonymous ,

 

I have done this for Top2, you can change the value in TOPN function to 5.

 

If you want to show in matrix format.

1.jpg

 

 

Link to the file.

https://drive.google.com/file/d/1nMW9-djgSQlPPdUXvW2d0aFrqHrSXxU0/view?usp=sharing

 

 

 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

 

 

View solution in original post

Anonymous
Not applicable

https://blog.gbrueckl.at/2019/05/power-bi-dynamic-topn-others-with-drill-down/

The link above has all you need to do this and even be able to drill down using the Other group.

Best
D

View solution in original post

14 REPLIES 14
Anonymous
Not applicable

https://blog.gbrueckl.at/2019/05/power-bi-dynamic-topn-others-with-drill-down/

The link above has all you need to do this and even be able to drill down using the Other group.

Best
D
Anonymous
Not applicable

Thank you @Anonymous ,

this link is perfectly describing the solution!

 

regards,

Dario 

 

Anonymous
Not applicable

Hi everyone,

thanks to who already answered, specially @harshnathani and @Anonymous  for best solution for my situation.

 

There's something more I want to ask for, that's my result (top 5 and other):
immagine.png

 

Now if possible, I would like the graphic to show first the values of top 5 (in descending order), then at the end always the value of others, not depending on its size.

 

Regards, 

Dario

harshnathani
Community Champion
Community Champion

Anonymous
Not applicable

Hi @harshnathani ,

thanks for the reply, 

I've had already seen that solution but it cannot solve my issue because the calculated column is static and doesn't refer to the measure. 

I also tried something like this https://www.minceddata.info/2018/06/06/topsomething-and-all-the-rest-called-other/ 

but it gives me an error

@Anonymous ,

 

Can you pls share same data and formula of your measure .

 

Regards,

Harsh Nathani

Anonymous
Not applicable

My table is like:

Order IDProduct NameSalesProfit
1Bike12010
2Ball402
3Bike20025
4Bike25020
5Table10040

 

I have create this [measure] that, as the user select sales/profit, it returns total sales or total profit; 
What I want to do is create a measure that can show the top 5 products and the others total value in the same graphic and can change the values related on what the user select in the first [measure].

 

@Anonymous ,

 

are Sales and Profit measures or Column,

 

and if they are measure, how can a user Select Sales or Profit. Do you have a different table for selection?

 

Regards,

HN

Anonymous
Not applicable

Yes well:

sales and profit are columns

for the selection I've create a disconnected table with only two data, "Total sales" (type: abc) and "Total profit" (type: abc), connected to the relative measure ( just a sum) so that, thanks to a switch, the user can select a word in the dashboard that changes the values due tu the context; 

in this scenario I want to create the topx and others graphic.

Hi @Anonymous ,

 

I have done this for Top2, you can change the value in TOPN function to 5.

 

If you want to show in matrix format.

1.jpg

 

 

Link to the file.

https://drive.google.com/file/d/1nMW9-djgSQlPPdUXvW2d0aFrqHrSXxU0/view?usp=sharing

 

 

 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

 

 

Hi,

I got it working like described in the article you shared, which is very impressively done by that guy! Wow.

 

I used the table you provided and added a few more rows. Below you see it working for a top 2 scenario.

topn.png

code:

topnmeasure = 
var __top = CALCULATETABLE(TOPN(2;VALUES('Table'[Product Name]);CALCULATE(SUM('Table'[Sales]))))
var __other = ROW("Product Name";"Other")
var __allTheRest = CALCULATE(SUM('Table'[Sales]);EXCEPT(VALUES('Table'[Product Name]);__top))
var __theUnion = UNION(__top;__other)
var __selectedproduct = SELECTEDVALUE('Table (2)'[Product Name];"Multiple")
return
//CONCATENATEX(__top;[Product Name] & "m: " & [Measure])
//CONCATENATEX(__theUnion;[Product Name] & " m:" & [Measure])
//CONCATENATEX(INTERSECT('Table (2)';__theUnion);[Product Name] & " m:" & [Measure]) // it now has the top products and the other category
SUMX(INTERSECT('Table (2)';__theUnion); IF('Table (2)'[Product Name]<>"Other"; CALCULATE(SUM('Table'[Sales]);'Table'[Product Name]=__selectedproduct);__allTheRest))

Link to the Power BI file here.

Hope this helps to move you forward, if so please mark as solution. Kudo's for the effort are appreciated.

Kind regards,  Steve. 

Anonymous
Not applicable

Hi Steve,

 

I think that's the way of think to get the solution, but I still have problems with that 'table2'; I don't understand what it is.

 

Thanks for the answer,

 

regards Dario

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

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

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.