Forum Discussion
TOPN dax function as variable
Need to show top 5 services in table visual.
| Service Name | Count | Total Count |
| Apple | 43 | 346 |
| Samsumg | 67 | 346 |
| mi | 80 | 346 |
| oppo | 84 | 346 |
| 72 | 346 |
Measure written we not able to do sum the count of all Services,
14 Replies
- v-yadongf-msftCommunity Support
Hi raj777karthik ,
This is my test table:
Please try following DAX to create a new table:
New Table = TOPN(5,SUMMARIZE('Stack Tags','Stack Tags'[Service],'Stack Tags'[Thread__]),'Stack Tags'[Thread__],DESC)Then create a measure to calculate total count:
Total count = CALCULATE(SUMX('New Table',CALCULATE(SUM('New Table'[Thread__]))),ALL('New Table'))You will get result you want:
If I misunderstand your demands, please feel free to contact us in time.
Best regards,
Yadong Fang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- raj777karthikMicrosoft Employee
Hi,
Thanks for this approach,but we need to do this in existing table considering relationship.If i create table function then only few slicer interacting and not all.
- v-yadongf-msftCommunity Support
Hi raj777karthik ,
If you don't want to create a new table, pleaser try following DAX to sort [Thread_] column:
Rank = RANKX('Stack Tags','Stack Tags'[Thread__],'Stack Tags'[Thread__],DESC)Calculate the sum of the top 5:
Total count = CALCULATE(SUM('Stack Tags'[Thread__]),FILTER(ALL('Stack Tags'),'Stack Tags'[Rank]<=5))Add the [Rank] column to Filters to filter out the top5:
Best regards,
Yadong Fang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- raj777karthikMicrosoft Employee
In this since my service oppo has 84 count the rank is taking all these for 1 and second service mi has 80 count ,rank is taken as 85 .And for third its taking as rank 165.