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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
RichOB
Helper V
Helper V

Need help with Topn Measure 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

LocationIssueIssue_Number
ManchesterAggressionIssue1
ManchesterAggressionIssue2
ManchesterAggressionIssue3
ManchesterAggressionIssue4
ManchesterNeglectIssue5
ManchesterNeglectIssue6
EdinburghNeglectIssue7
EdinburghViolenceIssue8
EdinburghViolenceIssue9
EdinburghViolenceIssue10
EdinburghViolenceIssue11
EdinburghNeglectIssue12
NewcastleEmotionalIssue13
NewcastleViolenceIssue14
NewcastleAggressionIssue15
NewcastleEmotionalIssue16
NewcastleEmotionalIssue17
NewcastleEmotionalIssue18


Table2

EdinburghViolence4
Manchester Aggression4
NewcastleNeglect4

 

 

 

 

Thanks

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

These measures work

Predominant issue = FIRSTNONBLANK ( TOPN ( 1, VALUES ( Data[Issue] ), [Issue count] ),1)
Measure = MAXX (VALUES(Data[Issue]), [Issue count] )

Hope this helps.

Ashish_Mathur_0-1739243295938.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi @Ashish_Mathur thanks for getting back to me. Where exactly is [issue_count] coming from? Are you making a measure of the individual counts first? thanks

You are welcome.  It is a measure

Issue count = counta(data[issue number])


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-jtian-msft
Community Support
Community Support

Hi,Jihwan_Kim ,thanks for your concern about this issue.

Your answer is excellent!
And I would like to share some additional solutions below.
Hello,@RichOB .I am glad to help you.
Like this?

vjtianmsft_0-1739241473943.png

In order to distinguish the data between Location groups, I added two extra lines of test data.

vjtianmsft_1-1739241561933.png

I created three measures and eventually created a calculated table to store the final summarized data
The measures I created:

 

M_groupNum01 = 
VAR _lacation = MAX ( 'IssueTable'[Location] )
VAR _issue = MAX ( 'IssueTable'[Issue] )
VAR _issueNumber = MAX ( 'IssueTable'[Issue_Number] )
VAR _result =
    CALCULATE (
        COUNT ( 'IssueTable'[Issue] ),
        FILTER (
            ALL ( IssueTable ),
            'IssueTable'[Location] = _lacation
                && 'IssueTable'[Issue] = _issue
        )
    ) // or use ALLEXCEPT() function
RETURN
    _result

 

 

 

M_maxNum02 = 
MAXX ( ALLEXCEPT ( IssueTable, IssueTable[Location] ), [M_groupNum01] )

 

 

 

Top Issue = 
CALCULATE (
    MAX ( 'IssueTable'[Issue] ),
    FILTER (
        ALLEXCEPT ( 'IssueTable', IssueTable[Location] ),
        [M_groupNum01] = [M_maxNum02]
    )
)

 

vjtianmsft_2-1739241705921.png

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Carson Jian,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

It is for creating a measure.

 

Jihwan_Kim_1-1739208861923.png

 

 

Jihwan_Kim_0-1739208841639.png

 

WINDOW function (DAX) - DAX | Microsoft Learn

 

Top 1 #count by location: = 
VAR _tononetable =
    WINDOW (
        1,
        ABS,
        1,
        ABS,
        ALL ( Issue[Issue] ),
        ORDERBY ( CALCULATE ( COUNTROWS ( Data ) ), DESC )
    )
RETURN
    IF (
        HASONEVALUE ( Location[Location] ),
        CALCULATE ( COUNTROWS ( Data ), KEEPFILTERS ( _tononetable ) )
    )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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