Forum Discussion

RichOB's avatar
RichOB
Icon for Post Partisan rankPost Partisan
1 year ago
Solved

Top 3 categories based on count

Hi, using the table below, how can I get the top 3 categories based on the count totals please?

 

LocationCategoryCount
BirminghamBike1
BirminghamBike1
BirminghamBike1
BirminghamCanoe1
BirminghamCanoe1
BirminghamKayak1
BirminghamCanoe1
BirminghamCanoe1
BirminghamCanoe1
BirminghamKayak1
BirminghamScooter1
BirminghamScooter1
BirminghamCanoe1
LiverpoolScooter1
LiverpoolScooter1
LiverpoolScooter1
LiverpoolKayak1
LiverpoolKayak1
LiverpoolKayak1
LiverpoolBike1
LiverpoolCanoe1
LiverpoolCanoe1
GlasgowKayak1
GlasgowKayak1
GlasgowKayak1
GlasgowKayak1
GlasgowCanoe1
GlasgowBike1
GlasgowBike1
GlasgowBike1
GlasgowScooter1
GlasgowSkates1
GlasgowSkates1


This is how I want the top 3 table to look please:

LocationCategoryCount
BirminghamCanoe6
BirminghamBike3
BirminghamKayak2
LiverpoolScooter3
LiverpoolKayak3
LiverpoolCanoe2
GlasgowKayak4
GlasgowBike3
GlasgowSkates2


Thanks

  • Try this ...

    Total = SUM(yourdata[Count])

     

    Ranker = 
    RANKX(
        all(yourdata[Category]),[total],,DESC)

     

    Draw a matrix to test the Rank is ok

     

    Add a filter to just select the top 3 using the ranker

     

     

     

    Please click thumbs up because I hace tried to help.

     

    The click accept solution if it works. Thank you.

     

    Leran more about RANKX here ...

    https://www.youtube.com/watch?v=eb_-i_hWSDI 

     

7 Replies

  • Try this ...

    Total = SUM(yourdata[Count])

     

    Ranker = 
    RANKX(
        all(yourdata[Category]),[total],,DESC)

     

    Draw a matrix to test the Rank is ok

     

    Add a filter to just select the top 3 using the ranker

     

     

     

    Please click thumbs up because I hace tried to help.

     

    The click accept solution if it works. Thank you.

     

    Leran more about RANKX here ...

    https://www.youtube.com/watch?v=eb_-i_hWSDI 

     

  • You can create a measure like

    Rank =
    RANK (
        ALLSELECTED ( 'Table'[Location], 'Table'[Category] ),
        ORDERBY ( CALCULATE ( SUM ( 'Table'[Count] ) ), DESC ),
        PARTITIONBY ( 'Table'[Location] )
    )
    

    add apply that as a filter to the table visual, set to show when the value is less than or equal to 3

  • RichOB 

    Create a new table to summarize the counts by Location and Category. You can do this by using the following DAX formula:

    SummaryTable =
    SUMMARIZE(
    'YourTable',
    'YourTable'[Location],
    'YourTable'[Category],
    "TotalCount", SUM('YourTable'[Count])
    )

     

    Add a rank column to rank the categories within each location based on the count. Use the following DAX formula:

    SummaryTableWithRank =
    ADDCOLUMNS(
    SummaryTable,
    "Rank", RANKX(
    FILTER(
    SummaryTable,
    [Location] = EARLIER([Location])
    ),
    [TotalCount],
    ,
    DESC,
    DENSE
    )
    )

     

    Finally, filter the table to show only the top 3 categories for each location. You can do this by creating a new table with the following DAX formula:

    Top3Categories =
    FILTER(
    SummaryTableWithRank,
    [Rank] <= 3
    )

     

    Use the Top3Categories table to create your desired visualizations in Power BI.

     

  • v-achippa's avatar
    v-achippa
    Icon for Community Support rankCommunity Support

    Hi RichOB,

     

    Thank you for reaching out to Microsoft Fabric Community.

     

    Thank you speedrampsbhanu_gautam , johnt75 for the prompt response.

     

    As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided by the user's resolved your issue? or let us know if you need any further assistance.
    If any response resolved your issue, please mark it as "Accept as solution" and give a kudos if you found it helpful.

     

    Thanks and regards,

    Anjan Kumar Chippa

    • v-achippa's avatar
      v-achippa
      Icon for Community Support rankCommunity Support

      Hi @RichOB,

       

      We wanted to kindly follow up to check if the solution provided by the user's resolved your issue?
      If any response resolved your issue, please mark it as "Accept as solution" and give a kudos if you found it helpful.

       

      Thanks and regards,

      Anjan Kumar Chippa

      • v-achippa's avatar
        v-achippa
        Icon for Community Support rankCommunity Support

        Hi @RichOB,

         

        As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided by the user's resolved your issue? or let us know if you need any further assistance.

         

        Thanks and regards,

        Anjan Kumar Chippa

  • Hi RichOB 

     

    I went to a lot of effort to provide an explanation and example.
    Did you try my method?

    Please click thumbs up and the [accept as solution] buttons.

    It is polite and sensible to thank helpers this way.  😀