Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

write DAX for TOP 5 AND BOTTOM 5

hi All

 

i have two columns

countrymatching
Francemanual match
Australiaauto match
Australiamanual match
UKauto match
Australiaauto match
UKmanual match
Germanyauto match
Germanyauto match
UKauto match
Francemanual match
Australiaauto match
Germanyauto match
UKauto match
UKauto match
USAmanual match
Franceauto match
Germanyauto match
Franceauto match
Australiaauto match
USAauto match
USAmanual match
Canadamanual match
UKauto match
Australiaauto match
Francemanual match
Australiaauto match
Canadaauto match
Australiaauto match
Germanymanual match
Francemanual match
Canadaauto match
Canadamanual match
Francemanual match
USAmanual match
Germanymanual match
Germanyauto match
Canadaauto match
Canadamanual match
Australiamanual match
Australiaauto match
Australiaauto match
Australiamanual match
USAmanual match
USAauto match
Germanyauto match
Franceauto match
Franceauto match
Francemanual match
Canadamanual match
USAauto match
Francemanual match
USAmanual match
Germanyauto match
Franceauto match
Germanyauto match
Francemanual match
USAauto match
Australiaauto match
Canadaauto match

 

need a slicer to switch top 5 and bottom 5 

1 top 5 auto match and top 5 manual match with countires and 

2 bottom 5 auto match and bottom 5 manual match with countires. please share powerbi file (using clustred column chart)

 

Regards

Dilip

  • Hi Anonymous 

    Thank you for being part of the Microsoft Fabric Community.

    As highlighted by bhanu_gautam ThxAlot, the proposed approach appears to effectively address your requirements. Could you please confirm if your issue has been resolve

    If you are still facing any challenges, kindly provide further details, and we will be happy to assist you.

    Best regards,
    Cheri Srikanth

6 Replies

  • Anonymous Create a calculated column for counting occurrences

    MatchCount =
    CALCULATE(
    COUNTROWS('Table'),
    ALLEXCEPT('Table', 'Table'[Country], 'Table'[Matching])
    )

     

     Create measures for top 5 and bottom 5 auto match and manual match

    Top5AutoMatch =
    CALCULATE(
    [MatchCount],
    FILTER(
    'Table',
    'Table'[Matching] = "auto match"
    ),
    TOPN(5, ALL('Table'[Country]), [MatchCount], DESC)
    )

    Bottom5AutoMatch =
    CALCULATE(
    [MatchCount],
    FILTER(
    'Table',
    'Table'[Matching] = "auto match"
    ),
    TOPN(5, ALL('Table'[Country]), [MatchCount], ASC)
    )

    Top5ManualMatch =
    CALCULATE(
    [MatchCount],
    FILTER(
    'Table',
    'Table'[Matching] = "manual match"
    ),
    TOPN(5, ALL('Table'[Country]), [MatchCount], DESC)
    )

    Bottom5ManualMatch =
    CALCULATE(
    [MatchCount],
    FILTER(
    'Table',
    'Table'[Matching] = "manual match"
    ),
    TOPN(5, ALL('Table'[Country]), [MatchCount], ASC)
    )

     

    Create a new table for the slicer:

    SlicerTable =
    DATATABLE(
    "Selection", STRING,
    {
    {"Top 5"},
    {"Bottom 5"}
    }
    )

     

    Create a measure to switch between top 5 and bottom 5:

    DAX
    SelectedMatchType =
    SWITCH(
    SELECTEDVALUE('SlicerTable'[Selection]),
    "Top 5", [Top5AutoMatch] + [Top5ManualMatch],
    "Bottom 5", [Bottom5AutoMatch] + [Bottom5ManualMatch]
    )

     

     

    Add a clustered column chart to your report.
    Add Country to the Axis.
    Add SelectedMatchType to the Values.
    Add the SlicerTable to the report and use it as a slicer

    • Anonymous's avatar
      Anonymous
      Not applicable

      thanks for responding 

      1 in chart it was showing the single bar but i need 2 bars one is auto match and manual match 

      2 when i select bottom 5 it was bottom 6 

      please share powerbi file 

       

       

  • Anonymous's avatar
    Anonymous
    Not applicable

    Thanks for the replies from ThxAlot and bhanu_gautam.

     

    Hi Anonymous ,

     

    Have you solved your problem? If it is solved, please mark the reply that help you as solution, it will be helpful for other members of the community who have similar problems as yours to solve it faster. If there are any more questions, please feel free to let us know. Thanks a lot!

     

    Best Regards,
    Zhu

     

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

    Hi Anonymous 

    Thank you for being part of the Microsoft Fabric Community.

    As highlighted by bhanu_gautam ThxAlot, the proposed approach appears to effectively address your requirements. Could you please confirm if your issue has been resolve

    If you are still facing any challenges, kindly provide further details, and we will be happy to assist you.

    Best regards,
    Cheri Srikanth

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

    Hi Anonymous 

    We haven't heard from you since last response and just wanted to check whether the solution provided has worked for you. If yes, please Accept as Solution to help others benefit in the community.
    Thank you.

    If the above information is helpful, please give us Kudos and mark the response as Accepted as solution.
    Best Regards,
    Community Support Team _ C Srikanth.