Forum Discussion
Obtaining Top 3 by Amounts
Hi, using the table below, I need to obtain the top 3 categories by Amount grouped by Location please. How can this be done?
Table1
| Locaiton | Category | Amount |
| Birmingham | Bike | £1,400 |
| Birmingham | e-Bike | £2,300 |
| Birmingham | Scooter | £700 |
| Birmingham | Kayak | £1,900 |
| Birmingham | Canoe | £800 |
| Liverpool | Bike | £3,000 |
| Liverpool | e-Bike | £1,900 |
| Liverpool | Scooter | £800 |
| Liverpool | Kayak | £6,000 |
| Liverpool | Canoe | £4,000 |
| Glasgow | Bike | £700 |
| Glasgow | e-Bike | £800 |
| Glasgow | Scooter | £1,900 |
| Glasgow | Kayak | £2,300 |
| Glasgow | Canoe | £1,200 |
Top3 Categories by Amount, grouped by countries:
| Locaiton | Top_3_Category | Amount |
| Birmingham | e-Bike | £2,300 |
| Birmingham | Kayak | £1,900 |
| Birmingham | Bike | £1,900 |
| Liverpool | Kayak | £6,000 |
| Liverpool | Canoe | £4,000 |
| Liverpool | Bike | £3,000 |
| Glasgow | Kayak | £2,300 |
| Glasgow | Scooter | £1,900 |
| Glasgow | Canoe | £1,200 |
Thanks
Hi RichOB,
Please use the DAX logic to get Top3 Categories by Location by Amount.Top3_Amount = VAR CurrentCategory = SELECTEDVALUE('Table'[Category]) VAR CurrentLocation = SELECTEDVALUE('Table'[Locaiton]) VAR RankCategory = RANKX ( FILTER ( ALL ( 'Table' ), 'Table'[Locaiton] = CurrentLocation ), CALCULATE ( SUM ( 'Table'[Amount] ) ), , DESC, DENSE ) RETURN IF ( RankCategory <= 3, CALCULATE ( SUM ( 'Table'[Amount] ) ) )Thanks,
If you found this solution helpful, please consider giving it a Like👍 and marking it as Accepted Solution✔. This helps improve visibility for others who may be encountering/facing same questions/issues.
5 Replies
- ajaybabuinturi
Super User
Hi RichOB,
Please use the DAX logic to get Top3 Categories by Location by Amount.Top3_Amount = VAR CurrentCategory = SELECTEDVALUE('Table'[Category]) VAR CurrentLocation = SELECTEDVALUE('Table'[Locaiton]) VAR RankCategory = RANKX ( FILTER ( ALL ( 'Table' ), 'Table'[Locaiton] = CurrentLocation ), CALCULATE ( SUM ( 'Table'[Amount] ) ), , DESC, DENSE ) RETURN IF ( RankCategory <= 3, CALCULATE ( SUM ( 'Table'[Amount] ) ) )Thanks,
If you found this solution helpful, please consider giving it a Like👍 and marking it as Accepted Solution✔. This helps improve visibility for others who may be encountering/facing same questions/issues. - v-menakakota
Community Support
Hi RichOB ,
Thanks for reaching out to the Microsoft fabric community forum.
I would also take a moment to thank ajaybabuinturi , for actively participating in the community forum and for the solutions you’ve been sharing in the community forum. Your contributions make a real difference.
May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.
Best Regards,
Menaka Kota
Community Support Team- v-menakakota
Community Support
Hi RichOB ,
May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.
Thank you.
- v-menakakota
Community Support
Hi RichOB ,
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If the response has addressed your query, please accept it as a solution so that other community members can find it easily.
Thank you.
- pankajnamekar25
Super User
Hello RichOB
Create a Rank Measure
Category Rank by Location =
VAR CurrentCategory = SELECTEDVALUE('Table'[Category])
VAR CurrentLocation = SELECTEDVALUE('Table'[Locaiton])
RETURN
RANKX(
FILTER(
ALL('Table'),
'Table'[Locaiton] = CurrentLocation
),
CALCULATE(SUM('Table'[Amount])),
,
DESC,
DENSE
)
Create the Final Measure for Top 3 Amounts
Top 3 Amounts by Location =
VAR RankValue = [Category Rank by Location]
RETURN
IF(RankValue <= 3, CALCULATE(SUM('Table'[Amount])))
Thanks
If this solution helps, please accept it and give a kudos (Like), it would be greatly appreciated.