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
esims123
Regular Visitor

Help with Top N

I want to have the top 5 sites appearing within my dataset by each month.

 

Currently I can only get the top 5 appearing overall rather than depending on month. 

 

The collumn "Created" is the date the site appeared however when I try to incoperate this it doesn't appear how I need it to be.

 

esims123_0-1700833687461.png

 

 

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @esims123 ,

Please try this:

SiteTop5 =
VAR _table =
    GENERATE (
        ALLSELECTED ( 'Heater Callout Data'[Created].[Month] ),
        TOPN (
            5,
            ALLSELECTED ( 'Heater Callout Data'[Site] ),
            COUNT ( 'Heater Callout Data'[Site] )
        )
    )
VAR _result =
    CALCULATE ( COUNT ( 'Heater Callout Data'[Site] ), KEEPFILTERS ( _table ) )
RETURN
    _result

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @esims123 ,

Please try create a new measure:

SiteTop5 = 
VAR _table = 
GENERATE(
    ALLSELECTED('Calendar'[Month]),
    TOPN(
        5,
        ALLSELECTED('Heater Callout Data'[Site]),
        [CountofSite]
    )
)
VAR _result = CALCULATE([CountofSite],KEEPFILTERS(_table))
RETURN
_result

And apply it to the y-axis.

Ranking – DAX Patterns

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

esims123_0-1701074773912.png

hey, couldnt get this to work, thanks

Anonymous
Not applicable

Hi @esims123 ,

Please try this:

SiteTop5 =
VAR _table =
    GENERATE (
        ALLSELECTED ( 'Heater Callout Data'[Created].[Month] ),
        TOPN (
            5,
            ALLSELECTED ( 'Heater Callout Data'[Site] ),
            COUNT ( 'Heater Callout Data'[Site] )
        )
    )
VAR _result =
    CALCULATE ( COUNT ( 'Heater Callout Data'[Site] ), KEEPFILTERS ( _table ) )
RETURN
    _result

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

that's great thanks, do you know if theres a way to select the top 5 without there being multiples who are within the top 5. For example there are several sites that have the same number of callouts which mean there are several sites within the top 5 rather than just 5.

 

thanks

 

esims123_0-1701079234846.png

 

amitchandak
Super User
Super User

@esims123 , use a measure created with TOPN or window

 

CALCULATE([meausre],TOPN(5,all(Table[site]),[Measure],DESC),VALUES(Table[site]))

 

 

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.