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
weilip1803
Frequent Visitor

Topn Function.

Hi I want to know how to use the topN function. Currently I am having a count row measure and I only want to display the top 10 results of my group how do I do it?

1 ACCEPTED SOLUTION
v-caliao-msft
Employee
Employee

Hi Weilip,

 

According to your description, you need to get the top 10 count for your group, right?

 

I have tested it on my local environment, the steps below are for you reference.

  1. Create a calculated column in your original table using the expression below.
    Count=CALCULATE(COUNTA(Sheet1[Subgroup]),ALLEXCEPT(Sheet1,Sheet1[GroupName]))
  2. Create a new table use the expression below
    TOP10 = TOPN(10,SUMMARIZE(Original,Original[GroupName]),[Measure])
  3. Add a new column in new created table.
    Count = LOOKUPVALUE(Original[count],Original[GroupName],'TOP10'[GroupName])

Capture.PNG

 

Regards,

Charlie Liao

View solution in original post

4 REPLIES 4
v-caliao-msft
Employee
Employee

Hi Weilip,

 

According to your description, you need to get the top 10 count for your group, right?

 

I have tested it on my local environment, the steps below are for you reference.

  1. Create a calculated column in your original table using the expression below.
    Count=CALCULATE(COUNTA(Sheet1[Subgroup]),ALLEXCEPT(Sheet1,Sheet1[GroupName]))
  2. Create a new table use the expression below
    TOP10 = TOPN(10,SUMMARIZE(Original,Original[GroupName]),[Measure])
  3. Add a new column in new created table.
    Count = LOOKUPVALUE(Original[count],Original[GroupName],'TOP10'[GroupName])

Capture.PNG

 

Regards,

Charlie Liao

TOP10 = TOPN(10,SUMMARIZE(Original,Original[GroupName]),[Measure])

 

Can the value ' 10' be dynamically selected?  ---topn[topnvalue]

 

If I try to replace it with [SelectedTopNNumber] where [SelectedTopNNumber]=value(topn[topnvalue]) , it throws me the below error,

MdxScript(Model) (17, 35) A table of multiple values was supplied where a single value was expected

@v-caliao-msftFantastic, Helped me out a lot!

Baskar
Resident Rockstar
Resident Rockstar

Hi weilip,

 

Do you want to show Top N Group by Count of Row measures Right ?

 

If yes please follow the below steps it will help u ...

 

1. Create new measure

 

Measure Count = count("Count row of Measures")

 

2. Create Rank Function

 

Rank = RankX(Allselected("Group"),Measure Count,,Asc,Dense)

 

3. Drag the rank field in Visual filter and choose what ever Top value u want.

 

let me know the feedback

 

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.