Forum Discussion
write DAX for TOP 5 AND BOTTOM 5
hi All
i have two columns
| country | matching |
| France | manual match |
| Australia | auto match |
| Australia | manual match |
| UK | auto match |
| Australia | auto match |
| UK | manual match |
| Germany | auto match |
| Germany | auto match |
| UK | auto match |
| France | manual match |
| Australia | auto match |
| Germany | auto match |
| UK | auto match |
| UK | auto match |
| USA | manual match |
| France | auto match |
| Germany | auto match |
| France | auto match |
| Australia | auto match |
| USA | auto match |
| USA | manual match |
| Canada | manual match |
| UK | auto match |
| Australia | auto match |
| France | manual match |
| Australia | auto match |
| Canada | auto match |
| Australia | auto match |
| Germany | manual match |
| France | manual match |
| Canada | auto match |
| Canada | manual match |
| France | manual match |
| USA | manual match |
| Germany | manual match |
| Germany | auto match |
| Canada | auto match |
| Canada | manual match |
| Australia | manual match |
| Australia | auto match |
| Australia | auto match |
| Australia | manual match |
| USA | manual match |
| USA | auto match |
| Germany | auto match |
| France | auto match |
| France | auto match |
| France | manual match |
| Canada | manual match |
| USA | auto match |
| France | manual match |
| USA | manual match |
| Germany | auto match |
| France | auto match |
| Germany | auto match |
| France | manual match |
| USA | auto match |
| Australia | auto match |
| Canada | auto 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
- bhanu_gautam
Super User
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- AnonymousNot 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
- ThxAlot
Super User
- AnonymousNot 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
Community 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
Community 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.