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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
elizabethvieira
Regular Visitor

Determine topN

Hi all, 

 

I want to determine the top 5 areas by number of publications. I would like to represent the result in a pie chart. I do not want to use the filter option available in the filter pane.

I have the table that follows, and the count of UT gives the number of publications (this identifies a publication).

https://drive.google.com/file/d/1RvVzMcNi3Tpm5iioeopaOf8hsXzKWm34/view?usp=drive_link 

 

My expected result is as follows:

 

fivearea
194Maternal Mortality
128Group B Streptococcus
91Bilirubin
90Gestational Mellitus
64Preterm Labor

 

 

At this moment, I am using the following formula, but I get all the areas and not the top 5.

 

 

 

 

SUMX(TOPN(5, SUMMARIZE('impact (2)', 'impact (2)'[area], "Total Articles", count('impact (2)'[UT])), [Total Articles], DESC), [Total Articles])

 

 

 

 

 

Thanks in advance,

Elizabeth Vieira

 

 

 

4 ACCEPTED SOLUTIONS
bhanu_gautam
Super User
Super User

@elizabethvieira , Try using below DAX

 

Top5Areas =
TOPN(
5,
SUMMARIZE(
'impact (2)',
'impact (2)'[area],
"Total Articles", COUNT('impact (2)'[UT])
),
[Total Articles],
DESC
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

Let's try different approach

 

First create a measure 

   PublicationCount = COUNT(TableName[UT])
 
Then create a new table by going to modelling tab 
TopAreas =
   TOPN(
       5,
       SUMMARIZE(
           TableName,
           TableName[Area],
           "PublicationCount", [PublicationCount]
       ),
       [PublicationCount],
       DESC
   )
 
@elizabethvieira , Did you tried to make table or measure?



Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

hello @elizabethvieira 

 

the TOPN from your link looks fine. I tried making an example and the result is good.

Left one is total sum and right one is sum of top 5 (exclude E and G as the lowest 2).

Irwan_0-1725500177661.png

 

also, if you want to show sum of top 5 in pie chart, you can do easier in visual filter as there is no calculation.

before visual filter

Irwan_6-1725501218526.png

 

after visual filter (put your areas in Legend and your value in Values, then your value again in By Value in visual filter option). in here, change from SUM to COUNT if you want to have count result.

Irwan_5-1725501037633.png

 

 

Hope this will help.

Thank you.

View solution in original post

Anonymous
Not applicable

Hi @elizabethvieira 

 

Thanks to Irwan and bhanu_gautam  for the quick reply and solution. The link you provided to the pbix file has privacy I can't open it. Here is my test data:

vtangjiemsft_0-1725504923129.png

(1) We can create measures.

Count = COUNT('impact (2)'[UT])
Index = 
var _table=SUMMARIZE(ALLSELECTED('impact (2)'),[area],"count",[Count])
RETURN RANKX(_table,[count],,DESC)

(2) We can create tables.

TopAreas = 
   TOPN(
       5,
       SUMMARIZE(
           'impact (2)',
           'impact (2)'[area],
           "PublicationCount", [Count]
       ),
       [PublicationCount],
       DESC
   )

vtangjiemsft_1-1725505018349.png

 

TopAreas2 = 
var _table=SUMMARIZE('impact (2)',[area],"count",[Count],"index",[Index])
RETURN SELECTCOLUMNS(FILTER(_table,[index]<=5),[area],[count])

vtangjiemsft_2-1725505056146.png

Best Regards,

Neeko Tang

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

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Hi @elizabethvieira 

 

Thanks to Irwan and bhanu_gautam  for the quick reply and solution. The link you provided to the pbix file has privacy I can't open it. Here is my test data:

vtangjiemsft_0-1725504923129.png

(1) We can create measures.

Count = COUNT('impact (2)'[UT])
Index = 
var _table=SUMMARIZE(ALLSELECTED('impact (2)'),[area],"count",[Count])
RETURN RANKX(_table,[count],,DESC)

(2) We can create tables.

TopAreas = 
   TOPN(
       5,
       SUMMARIZE(
           'impact (2)',
           'impact (2)'[area],
           "PublicationCount", [Count]
       ),
       [PublicationCount],
       DESC
   )

vtangjiemsft_1-1725505018349.png

 

TopAreas2 = 
var _table=SUMMARIZE('impact (2)',[area],"count",[Count],"index",[Index])
RETURN SELECTCOLUMNS(FILTER(_table,[index]<=5),[area],[count])

vtangjiemsft_2-1725505056146.png

Best Regards,

Neeko Tang

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

Many thanks to all. 

 

I fixed my issues. It is now working well. 

 

Best, 

 

Elizabeth

bhanu_gautam
Super User
Super User

@elizabethvieira , Try using below DAX

 

Top5Areas =
TOPN(
5,
SUMMARIZE(
'impact (2)',
'impact (2)'[area],
"Total Articles", COUNT('impact (2)'[UT])
),
[Total Articles],
DESC
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Many thanks, but when using the expression I get the following comment : 

 

"The expression refers to multiple columnsMultiple columns cannot be converted to a scalar value"

Let's try different approach

 

First create a measure 

   PublicationCount = COUNT(TableName[UT])
 
Then create a new table by going to modelling tab 
TopAreas =
   TOPN(
       5,
       SUMMARIZE(
           TableName,
           TableName[Area],
           "PublicationCount", [PublicationCount]
       ),
       [PublicationCount],
       DESC
   )
 
@elizabethvieira , Did you tried to make table or measure?



Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






I tried a measure. 

 

Following the suggestion, I get a table with all the counts by area. It seems that the function topn is not working as I get all the areas and not the top five. 

hello @elizabethvieira 

 

the TOPN from your link looks fine. I tried making an example and the result is good.

Left one is total sum and right one is sum of top 5 (exclude E and G as the lowest 2).

Irwan_0-1725500177661.png

 

also, if you want to show sum of top 5 in pie chart, you can do easier in visual filter as there is no calculation.

before visual filter

Irwan_6-1725501218526.png

 

after visual filter (put your areas in Legend and your value in Values, then your value again in By Value in visual filter option). in here, change from SUM to COUNT if you want to have count result.

Irwan_5-1725501037633.png

 

 

Hope this will help.

Thank you.

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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