Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hey,
Could someone please help me out with the following problem please?
If I have 5 animals for example with different values. I want to be able to rank the top three and then output the top 3 names and aggregte the remaining animals that didn't make it to the top 3.
Animal | Value | Rank |
Horses | 9 | 1 |
Chickens | 8 | 2 |
Frogs | 7 | 3 |
Dogs | 4 | 4 |
Cats | 1 | 5 |
Desired Output | ||
Animal | Value | |
Horses | 9 | |
Chickens | 8 | |
Frogs | 7 | |
Other | 5 |
Solved! Go to Solution.
Here is an example using Contoso dataset, but the idea is same. first create a rank column in your table based on the amount or anything.
ProductRank =
RANKX (
ALL ( Products[Brand] ),
CALCULATE ( [Total Sales], ALLEXCEPT ( Products, Products[Brand] ) ),
,
ASC
)
Now we create a new column to group the brands based on the ranking
NewProductCategory =
VAR ProductRank = Products[ProductRank]
VAR ProductBrand = Products[Brand]
VAR Result =
IF ( ProductRank IN { 1, 2, 3 }, ProductBrand, "Others" )
RETURN
Result
Now the final step is the put everything in a visualization
Total Sales = SUMX ( Sales, Sales[Quantity] * Sales[Net Price] )
Rank on Sales =
IF (
HASONEVALUE ( Products[NewProductCategory] ),
RANKX ( ALL ( Products[NewProductCategory] ), [Total Sales] )
)
Here is an example using Contoso dataset, but the idea is same. first create a rank column in your table based on the amount or anything.
ProductRank =
RANKX (
ALL ( Products[Brand] ),
CALCULATE ( [Total Sales], ALLEXCEPT ( Products, Products[Brand] ) ),
,
ASC
)
Now we create a new column to group the brands based on the ranking
NewProductCategory =
VAR ProductRank = Products[ProductRank]
VAR ProductBrand = Products[Brand]
VAR Result =
IF ( ProductRank IN { 1, 2, 3 }, ProductBrand, "Others" )
RETURN
Result
Now the final step is the put everything in a visualization
Total Sales = SUMX ( Sales, Sales[Quantity] * Sales[Net Price] )
Rank on Sales =
IF (
HASONEVALUE ( Products[NewProductCategory] ),
RANKX ( ALL ( Products[NewProductCategory] ), [Total Sales] )
)
You are a legend! Very much appreciated, thank you. 🙂
You're welcome, I am glad that I could help you. 🙂
Hi @Anonymous
Try this,
Top 3 and Others =
IF(
RANKX( 'Table', 'Table'[Value] ) <= 3,
'Table'[Animal],
"Others"
)
the rank formula will need to be adjusted if you have Animals duplicated in your table.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
97 | |
77 | |
66 | |
54 |
User | Count |
---|---|
144 | |
104 | |
102 | |
88 | |
63 |