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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

TOP N based on column

Hi Experts,

Sorry I tried to ask question here but probably I did not attriculate it well.

https://community.powerbi.com/t5/Desktop/Top-N-from-the-column/m-p/2531292#M897722

I am looking for TOP N of Different columns based on the Reasontype.

How to achieve this ?

TopN_help.PNG

Thanks a lot

2 REPLIES 2
isabella
Employee
Employee

Hi @Anonymous 

Top3 dept by reason and top 3 name by reason should be deal with seperately

 

Here are my steps,my approach is to filter the top3 reason ,then

Add column = Count the dept by reason ,then rank by reason and this  column

copy the table in power query

isabella_0-1653896369399.png

 

group by reason

isabella_1-1653896369399.png

 

isabella_2-1653896369400.png

 

sort count

isabella_3-1653896369400.png

 

 

Now the data looks as:

isabella_4-1653896369401.png

 

We can delete the bottom 2 row

isabella_5-1653896369401.png

 

 

isabella_6-1653896369402.png

 

 

isabella_7-1653896369402.png

 

Now the table looks as:

isabella_8-1653896369402.png

 

 

We can copy the table here ,for one to calculate to top 3 dept, the other one to calculate the top name

Then expand the dept column

isabella_9-1653896369404.png

 

 

isabella_10-1653896369405.png

 

remove the Count column

Then  group by reason and department

 

isabella_11-1653896369405.png

 

 

Then sort the reason

isabella_12-1653896369405.png

 

Then sort    the Count column

isabella_13-1653896369406.png

 

 

Then add index column( I need to explain why the index column is added here, because some counts are the same number, and if they are sorted by rankx later, they are also the same serial number, which cannot be distinguished, so I choose to add an index column, and then sum with the count, so that Can each department correspond to one unique sort number )

isabella_14-1653896369406.png

 

 

Sum the Count and index column

isabella_15-1653896369407.png

 

 

isabella_16-1653896369407.png

 

 

Delete the count and index column

Close and apply ,back to power bi desktop

Add column

rank by department = RANKX(FILTER'Table','Table'[Reason]=EARLIER('Table'[Reason])),'Table'[Addition],,,Dense)

 

isabella_17-1653896369408.png

 

 

In visualization

isabella_18-1653896369408.png

 

 

isabella_19-1653896369408.png

 

 

 

The above are the steps to obtain top 3 department by reason, and the same is true for obtaining top 3 name by reason .

 

 

Best Regards,

Community Support Team _Isabella

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

amitchandak
Super User
Super User

@Anonymous , refer this

https://www.sqlbi.com/articles/filtering-the-top-3-products-for-each-category-in-power-bi/

 

 

A meausre like this should help

calculate(count(Table[name]) ,TOPN(3,all(Table[Department]),calculate(count(Table[name]) )), values(Table[Department]))

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.