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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
bdehning
Post Prodigy
Post Prodigy

Need TOPN

I have the following measure and what do I add to show only the Top 5?

 

Rank Cause Grouping =
IF (
    ISINSCOPE(InjuryCause[Cause Grouping] ),
    RANKX(
        CALCULATETABLE(
            VALUES(InjuryCause[Cause Grouping] ),
            ALLSELECTED (InjuryCause[Cause Grouping] )
        ),
        LossRunToExcel[Count of Total Gross Incurred])
)
6 REPLIES 6
amitchandak
Super User
Super User

@bdehning , use a visual level filter, filter this for <=5

 

else create a TOPN -TOPN: https://youtu.be/QIVEFp-QiOk  in place of rank

 

 

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

I got that to work but I get ties and end up with more than 5 values.    As I use [Count of Total Gross Incurred] for the first calculation, how can I add the next calculation to check the [Sum of Total Gross Incurred] to break ties to stay at 5 or less?

TOPN can also deal with ties.

TOPN – DAX Guide

 

 

--  TOPN might return more than the requested rows in presence of ties.
EVALUATE
    TOPN (
        3,
        ADDCOLUMNS (
            VALUES ( 'Product'[Product Name] ),
            "@Sales Amount", MROUND ( [Sales Amount], 500000 )
        ),
        [@Sales Amount],
        DESC
    )
ORDER BY [@Sales Amount] DESC
 
--  Multiple sorting criteria can be provided in further parameters.
EVALUATE
    TOPN (
        3,
        ADDCOLUMNS (
            VALUES ( 'Product'[Product Name] ),
            "@Sales Amount", MROUND ( [Sales Amount], 500000 )
        ),
        [@Sales Amount],
        DESC,
        [Product Name],
        ASC
    )
ORDER BY [@Sales Amount] DESC

 

 

I already have a Top N in my Table to Select top 5 Cities.   

 

I need to create a new measure that can check Count of an item first and then use the highest sum of each item to break ties.  

 

This is what gets me the Top 5 when I use "Is Less than or greater to 5"

 
Rank Cause Grouping =
IF (
    ISINSCOPE(InjuryCause[Cause Grouping] ),
    RANKX(
        CALCULATETABLE(
            VALUES(InjuryCause[Cause Grouping] ),
            ALLSELECTED (InjuryCause[Cause Grouping] )
        ),
        LossRunToExcel[Count of Total Gross Incurred])
)

 

Now I need to be able to break ties by taking the highest Sum of counts that tie.   I will be using LossRunToExcel[Sum of Total Gross Incurred]

 

Ideas?

 

 

 

 

 

Hi, @bdehning 

Not sure what you mean.

Can you share your sample data and expected result? It's easier to take a look at the problem.

Best Regards,
Community Support Team _ Eason

Can you close this string out.  I had to work on another string.  

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.