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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Zana
New Member

Calculate top 5 and other

I am trying to select the top 5 states and other graphs

my dataset is 1000 startups 

these startups were founded in different states of course. I want to show them like 

 

state perc

CA    25

NY   20

Al    15

FL    12

Others 28

 

what should I do

7 REPLIES 7
Padycosmos
Solution Sage
Solution Sage

Tahreem24
Super User
Super User

  Try this measre:Top5 =
VAR _top5 =
    TOPN (
        5,
        ALLSELECTED ( TableName[State] ),
        CALCULATE ( SUM ( TableName[Perc] ) )DESC
    )
VAR CurrState =
    SELECTEDVALUE ( TableName[State] )
VAR result =
    IF ( CurrState IN top5, CurrState"Others" )
RETURN
    result

 

@Zana

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

Thank you @Tahreem24 

So I need first to build a perc field. 

Do you have any suggestions?

I have overview[state] field, it is better to build a new column as states[percentage], states table also has [state] filed for relation.

I should count all states themselves and divide by the total which is obviously 1000. But  I couldn't do this too.

 

Edit: Sorry It wasn't difficult, I made it 

 

@Zana For a Perc you need to create a measure like below:

Perc = 
VAR _statewise = CALCULATE(COUNT(TableName[State]))
VAR _total = CALCULATE(COUNT(TableName[State]),ALL(TableName))
RETURN DIVIDE(_statewise,_total,0)

 

Then follow my previous post formula to get the Top 5 and others.

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

is there any mistake on this row:

IF ( CurrState IN top5, CurrState, "Others" )

when I add _ in front of the top5 it works, like : 

IF ( CurrState IN _top5, CurrState, "Others" )

 

on the other hand, I made this but how should I see the results of this function? I didn't understand how can I use it. 

amitchandak
Super User
Super User

@Zana , refer my approach on the same

Power BI- Power BI- TOPN with Others- https://youtu.be/I_TY4hVlzAE

I give up on solving problems in these ways. I need more simple and sustainable solutions. Thanks for your helps. 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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