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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
KN8
Frequent Visitor

Top N filter + other

Hello Everyone,

 

I'm trying to achive TOP 3 + Other(Oracle) Companies by revenue  from the below table. I was able to get Top 3 by applying TOP N filter on the visual. 

How can we achieve  TOP N + "Other" (in this case other = "Oracle") ? 

 

Input Data :

DateCompanies Revenue
7/10/2021Google1000
8/15/2021Google1500
9/5/2021Apple1000
7/10/2021Facebook1000
8/11/2021Apple500
8/18/2021Microsoft800
9/14/2021IBM600
9/4/2021Oracle400
8/20/2021Tesla2000

 

Expected Output:

TOP 3 "Companies + Oracle" by Revenue

Companies Revenue
Google2500
Tesla2000
Apple1500
Oracle400

 

Thanks in advance for your help!!

2 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Picture2.png

 

Only show top3 and Oracle: =
VAR top3table =
TOPN ( 3, ALL ( Data[Companies] ), CALCULATE ( SUM ( Data[Revenue] ) ), DESC )
RETURN
IF (
HASONEVALUE ( Data[Companies] ),
SWITCH (
TRUE (),
SELECTEDVALUE ( Data[Companies] ) = "Oracle", SUM ( Data[Revenue] ),
CALCULATE ( SUM ( Data[Revenue] ), KEEPFILTERS ( top3table ) )
)
)

 

 

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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

Hi, 

Thank you for your message.

When you see the previous measure, there is a IF condition that says "if there is one company in the row, then show the result, otherwise blank".

if I do not write this, then it shows the wrong total, and I did not know whether readers want to see the total or not. I thought showing blank is better than showing a wrong total.

If you want to show the total, then please try the below.

 

Only show top3 and Oracle: =
VAR top3table =
TOPN ( 3, ALL ( Data[Companies] ), CALCULATE ( SUM ( Data[Revenue] ) ), DESC )
RETURN
SUMX (
VALUES ( Data[Companies] ),
CALCULATE (
SWITCH (
TRUE (),
SELECTEDVALUE ( Data[Companies] ) = "Oracle", SUM ( Data[Revenue] ),
CALCULATE ( SUM ( Data[Revenue] ), KEEPFILTERS ( top3table ) )
)
)
)
 
Picture2.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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

7 REPLIES 7
TheoC
Super User
Super User

Hi @KN8 

 

You can use SUMMARIZE to create a New Table using DAX:

New Table = SUMMARIZE ( 'Table' , Table[Companies] )

From there, you can use the below to rank the companies:

 

Top 3 Rank Companies = 

VAR _RankByRev = RANKX ( ALL ( 'New Table' ) , [Sum Revenue] , , DESC )

return

IF ( _RankByRev <=3 , 'New Table'[Companies] , "Other" )

This will return the top 3 names and all others as Other.  I assume you have a [Sum Revenue] which is just a SUM on the revenue column in your Table.  Outputs will be as per below:

 

TheoC_1-1635742761462.png

From here, you can use the [Top 3 Rank Companies] column as the basis of filtering and just drag the [Sum Revenue] measure as you require.

 

Hope this helps 🙂

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Picture2.png

 

Only show top3 and Oracle: =
VAR top3table =
TOPN ( 3, ALL ( Data[Companies] ), CALCULATE ( SUM ( Data[Revenue] ) ), DESC )
RETURN
IF (
HASONEVALUE ( Data[Companies] ),
SWITCH (
TRUE (),
SELECTEDVALUE ( Data[Companies] ) = "Oracle", SUM ( Data[Revenue] ),
CALCULATE ( SUM ( Data[Revenue] ), KEEPFILTERS ( top3table ) )
)
)

 

 

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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Thanks for the solution. May I know why it doesn't aggregate to grand total ?

KN8_0-1635895177812.png

 

Hi, 

Thank you for your message.

When you see the previous measure, there is a IF condition that says "if there is one company in the row, then show the result, otherwise blank".

if I do not write this, then it shows the wrong total, and I did not know whether readers want to see the total or not. I thought showing blank is better than showing a wrong total.

If you want to show the total, then please try the below.

 

Only show top3 and Oracle: =
VAR top3table =
TOPN ( 3, ALL ( Data[Companies] ), CALCULATE ( SUM ( Data[Revenue] ) ), DESC )
RETURN
SUMX (
VALUES ( Data[Companies] ),
CALCULATE (
SWITCH (
TRUE (),
SELECTEDVALUE ( Data[Companies] ) = "Oracle", SUM ( Data[Revenue] ),
CALCULATE ( SUM ( Data[Revenue] ), KEEPFILTERS ( top3table ) )
)
)
)
 
Picture2.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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Awesome thanks again for the explination and the solution. 

TheoC
Super User
Super User

Hi @KN8 

 

You can use SUMMARIZE to create a New Table using DAX:

New Table = SUMMARIZE ( 'Table' , Table[Companies] )

From there, you can use the below to rank the companies:

 

Top 3 Rank Companies = 

VAR _RankByRev = RANKX ( ALL ( 'New Table' ) , [Sum Revenue] , , DESC )

return

IF ( _RankByRev <=3 , 'New Table'[Companies] , "Other" )

This will return the top 3 names and all others as Other.  I assume you have a [Sum Revenue] which is just a SUM on the revenue column in your Table.  Outputs will be as per below:

 

TheoC_0-1635724542781.png

From here, you can use the [Top 3 Rank Companies] column as the basis of filtering and just drag the [Sum Revenue] measure as you require.

 

Hope this helps 🙂

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

TomMartens
Super User
Super User

Hey @KN8 ,

 

this article provides a solution on how to tackle your challenge: https://www.sqlbi.com/articles/showing-the-top-5-products-and-others-row/

 

Hopefully, this is what you are looking for.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.