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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
RichOB
Post Partisan
Post Partisan

TOPn help please

Hi, Using Table1 below, I'm looking to have a table visual in my report that looks like Table2, which shows the location with the highest number of issues related to it. Is there a way to do this using Top N? or another measure, please?

 

Table1

LocationIssue
ManchesterAggression
ManchesterAggression
ManchesterAggression
ManchesterAggression
ManchesterNeglect
ManchesterNeglect
EdinburghNeglect
EdinburghViolence
EdinburghViolence
EdinburghViolence
EdinburghViolence
EdinburghNeglect
NewcastleEmotional
NewcastleViolence
NewcastleAggression
NewcastleEmotional
NewcastleEmotional
NewcastleEmotional


Table2

EdinburghViolence4
Manchester Aggression4
NewcastleNeglect4

 

Thanks

1 ACCEPTED SOLUTION
speedramps
Super User
Super User

I have seen almost excatly the same question posted with same data over the last few days, and assume you are a from class of students who have been given the same exam homework.  I hope you are not cheating asking for help 🙄

 

The question contains a trick. What happens if a locations have mote than one issues which have the top number of incidents.

For example in this data London has 5 incidents of Theft and Drugs

 

Location Issue Incident
Manchester Aggression Incident 1
Manchester Aggression Incident 2
Manchester Aggression Incident 3
Manchester Aggression Incident 4
Manchester Neglect Incident 5
Manchester Neglect Incident 6
Edinburgh Neglect Incident 7
Edinburgh Violence Incident 8
Edinburgh Violence Incident 9
Edinburgh Violence Incident 10
Edinburgh Violence Incident 11
Edinburgh Neglect Incident 12
Newcastle Emotional Incident 13
Newcastle Violence Incident 14
Newcastle Aggression Incident 15
Newcastle Emotional Incident 16
Newcastle Emotional Incident 17
Newcastle Emotional Incident 18
London Theft Incident 19
London Theft Incident 20
London Theft Incident 21
London Theft Incident 22
London Theft Incident 23
London Drugs Incident 24
London Drugs Incident 25
London Drugs Incident 26
London Drugs Incident 27
London Drugs Incident 28
Manchester Theft Incident 29
Edinburgh Theft Incident 30
Newcastle Theft Incident 31
Manchester Theft Incident 32
Edinburgh Theft Incident 33
Newcastle Drugs Incident 34
Manchester Drugs Incident 35
Manchester Drugs Incident 36
Newcastle Drugs Incident 37

 

 

Click here to download my PBIX solution form Onedrive.

Please click thumbs up for the helpful suggestion

and click accept solution if it works.  You can accept multiple solutions in the thread,

Click here 

speedramps_1-1739270910382.png

How it works

 

Incidents = 
// get the number of incidents for the context
COUNTROWS(Facts)

 

 

 

Highest by location = 
VAR mylocation = SELECTEDVALUE(Facts[Location])
VAR mymaxvalue = 
MAXX(
    VALUES(Facts[Issue]),
    [Incidents]
)
RETURN
mymaxvalue

 



 

Issues with max = 
// get the current context location
VAR myissue = SELECTEDVALUE(Facts[Location])

// get the maxium number of incidents by issue for the current location
VAR mymaxvalue = 
MAXX(
    VALUES(Facts[Issue]),
    [Incidents]
)

// create a temp table of issues (just for the context location) that equal the max value
VAR mymaxissues =
FILTER(VALUES(Facts[Issue]), [Incidents] = mymaxvalue)

RETURN
// delimit
CONCATENATEX(mymaxissues,Facts[Issue], " ,")

 

 

If you download the PBIX you will see there are also measures to get the loactions with highest incident rate for each type of issue.

 

View solution in original post

4 REPLIES 4
speedramps
Super User
Super User

I have seen almost excatly the same question posted with same data over the last few days, and assume you are a from class of students who have been given the same exam homework.  I hope you are not cheating asking for help 🙄

 

The question contains a trick. What happens if a locations have mote than one issues which have the top number of incidents.

For example in this data London has 5 incidents of Theft and Drugs

 

Location Issue Incident
Manchester Aggression Incident 1
Manchester Aggression Incident 2
Manchester Aggression Incident 3
Manchester Aggression Incident 4
Manchester Neglect Incident 5
Manchester Neglect Incident 6
Edinburgh Neglect Incident 7
Edinburgh Violence Incident 8
Edinburgh Violence Incident 9
Edinburgh Violence Incident 10
Edinburgh Violence Incident 11
Edinburgh Neglect Incident 12
Newcastle Emotional Incident 13
Newcastle Violence Incident 14
Newcastle Aggression Incident 15
Newcastle Emotional Incident 16
Newcastle Emotional Incident 17
Newcastle Emotional Incident 18
London Theft Incident 19
London Theft Incident 20
London Theft Incident 21
London Theft Incident 22
London Theft Incident 23
London Drugs Incident 24
London Drugs Incident 25
London Drugs Incident 26
London Drugs Incident 27
London Drugs Incident 28
Manchester Theft Incident 29
Edinburgh Theft Incident 30
Newcastle Theft Incident 31
Manchester Theft Incident 32
Edinburgh Theft Incident 33
Newcastle Drugs Incident 34
Manchester Drugs Incident 35
Manchester Drugs Incident 36
Newcastle Drugs Incident 37

 

 

Click here to download my PBIX solution form Onedrive.

Please click thumbs up for the helpful suggestion

and click accept solution if it works.  You can accept multiple solutions in the thread,

Click here 

speedramps_1-1739270910382.png

How it works

 

Incidents = 
// get the number of incidents for the context
COUNTROWS(Facts)

 

 

 

Highest by location = 
VAR mylocation = SELECTEDVALUE(Facts[Location])
VAR mymaxvalue = 
MAXX(
    VALUES(Facts[Issue]),
    [Incidents]
)
RETURN
mymaxvalue

 



 

Issues with max = 
// get the current context location
VAR myissue = SELECTEDVALUE(Facts[Location])

// get the maxium number of incidents by issue for the current location
VAR mymaxvalue = 
MAXX(
    VALUES(Facts[Issue]),
    [Incidents]
)

// create a temp table of issues (just for the context location) that equal the max value
VAR mymaxissues =
FILTER(VALUES(Facts[Issue]), [Incidents] = mymaxvalue)

RETURN
// delimit
CONCATENATEX(mymaxissues,Facts[Issue], " ,")

 

 

If you download the PBIX you will see there are also measures to get the loactions with highest incident rate for each type of issue.

 

ryan_mayu
Super User
Super User

@RichOB 

you can try this

 

Measure = rankx(FILTER(all('Table'),'Table'[Location]=max('Table'[Location])),[count],,DESC)
 
and add this measure to visual filter and set to 1
 
11.PNG
pls see the attachment below
 
 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




AnushaSri
Resolver II
Resolver II

Hi @RichOB , You can achieve this by the feature available in power BI filters section, where you can follow the steps

1.Select table you want to apply Top N filter

2. go to filters. 

3. In your case select Location

4.Select filter type to Top N

5. Set the number of top rows you want to see on the table.

6.select the column/measure on what basis you want to filter location for Top N, in your case it seems count of issues.

AnushaSri_0-1739267072570.png

Hope it helps, Please mark it as a solution accepted, if it helps to resolve your issue.

amitchandak
Super User
Super User

@RichOB , First create a meausre say 

M1 = countrows(Table1) 

 

Then create another measure for top 3 location

calculate([M1], keepfilters(TOPN(3, allselected(Table[Location]), [M1], Desc) ) )

 

use that in visual with location

 

Also check Window function

 

Learn Power BI: Dynamic TOPN using TOPN/Window and Numeric parameter: https://youtu.be/vm2mdEioQPQ

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.