Forum Discussion

esims123's avatar
esims123
Regular Visitor
2 years ago
Solved

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.

 

 

 

 

 

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    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

5 Replies

  • Anonymous's avatar
    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

      • Anonymous's avatar
        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