Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
ushankar
Frequent Visitor

How to get top 5, Midle, and Bottm 5

Hi ,

 

I have an requirment to acheive 

Top 5 in Green , Bottom 5 in Red and other values in Purple.

I need to acheive this in scatter plot visualization.

Need your help. I have attached the data sheet that i'm using for this requirement. 

Thanks in advance

 

ProductSales VolumeRevenueRank
A33.55497189386Top5
B137.418922808754Top5
C272.034822142154Top5
D149.598311514751Top5
E214.186814848040Top5
F117.78017935856Normal
G175.58510154915Normal
H182.655710251254Normal
I183.768310227660Normal
J184.896810235825Normal
K238.470312649451Normal
M231.63512076366Normal
N161.21978377149Normal
O210.094610492270Normal
P197.63899818325Normal
Q156.37357416810Normal
S172.37158068115Normal
T156.6497205120Bottom5
U200.58228956852Bottom5
X176.84017862781Bottom5
Y159.62757083706Bottom5
Z181.77348002398Bottom5
1 ACCEPTED SOLUTION

Hey @ushankar ,

 

the solution provided by @Mariusz is much more elegant as the calculated column based solution I provided, but nevertheless it should tweaked a little.

 

I created a little pbix file, the scatter plot provides the same result, but used in a table the measure might create unexpected results as the following pictures shows:
image.png
For this reason I recommend to tweak the measure like so:

ms RANK ALL Table = 
VAR P = ALL('Table1') --table instead of Product column
VAR T = RANKX( P, CALCULATE(SUM('Table1'[SN])) ,,DESC) <= 5 -- replace [s] with your mesure
VAR B = RANKX( P, CALCULATE(SUM('Table1'[SN])) ,,ASC) <= 5 -- replace [s] with your mesure
RETURN 
SWITCH(
    TRUE(),
    T, "green", --is 1 then conditional format green 
    B, "red", --is 2 then conditional format red 
    "purple" --3 -- is 3 then conditional format purple
)


Regards,
Tom

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

6 REPLIES 6
Mariusz
Community Champion
Community Champion

Hi @ushankar ,

The below mesure shoud resolve your problem 

Spoiler
RANK = 
VAR P = ALL(Table1[Product]) --Product column
VAR T = RANKX( P, [s] ,,DESC) <= 5 -- replace [s] with your mesure
VAR B = RANKX( P, [s] ,,ASC) <= 5 -- replace [s] with your mesure
RETURN 
SWITCH(
    TRUE(),
    T, 1, --is 1 then conditional format green 
    B, 2, --is 2 then conditional format red 
    3 -- is 3 then conditional format purple
)

Use this mesure as conditonal formating.

 

Thanks

Mariusz

Hey @ushankar ,

 

the solution provided by @Mariusz is much more elegant as the calculated column based solution I provided, but nevertheless it should tweaked a little.

 

I created a little pbix file, the scatter plot provides the same result, but used in a table the measure might create unexpected results as the following pictures shows:
image.png
For this reason I recommend to tweak the measure like so:

ms RANK ALL Table = 
VAR P = ALL('Table1') --table instead of Product column
VAR T = RANKX( P, CALCULATE(SUM('Table1'[SN])) ,,DESC) <= 5 -- replace [s] with your mesure
VAR B = RANKX( P, CALCULATE(SUM('Table1'[SN])) ,,ASC) <= 5 -- replace [s] with your mesure
RETURN 
SWITCH(
    TRUE(),
    T, "green", --is 1 then conditional format green 
    B, "red", --is 2 then conditional format red 
    "purple" --3 -- is 3 then conditional format purple
)


Regards,
Tom

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Thanks Tom !

 

Your solution did really works for me.

TomMartens
Super User
Super User

Hey,

 

I guess this looks very close to your requirement 😉

image.png

To achieve this I created a measure:

vizAid FillColor = 
var thisRank = FIRSTNONBLANK('Table1'[Rank],0)
return
--"red"

SWITCH(
    thisRank
    ,"Top5", "green"
    ,"Normal", "purple"
    ,"Bottom5", "red"
    ,"blue"
)

To work properly it's necessary that the column "Product" is used on field weld "Details" of the Scatter chart visual:

image.png

Then I assigned the measure to the data color using conditional formatting:

image.png
and finally this:

image.png

Hopefully this is what you are looking.

 

Regards,

Tom

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Hi Tom,

 

Thanks for your quick reply. I was really quick.

 

My bad i did not articulate my requirement properly. According to the below table I want to rank on "SN" feild , the Rank column which i have mentioned is just for reference.

 

ProductSales VolumeRevenueSNRank
A33.55497189386214257Top5
B137.418922808754165980Top5
C272.03482214215481395Top5
D149.59831151475176971Top5
E214.18681484804069323Top5
F117.7801793585667379Normal
G175.5851015491557835Normal
H182.65571025125456123Normal
I183.76831022766055655Normal
J184.89681023582555360Normal
K238.47031264945153044Normal
L231.6351207636652135Normal
M161.2197837714951961Normal
N210.09461049227049941Normal
O197.6389981832549678Normal
P156.3735741681047430Normal
Q172.3715806811546807Normal
R156.649720512045995Bottom5
S200.5822895685244654Bottom5
T176.8401786278144463Bottom5
U159.6275708370644376Bottom5
V181.7734800239844024Bottom5

Hey,

 

you can create a calculated column using this DAX:

Column = 
var top5Product = 
    SELECTCOLUMNS(
    TOPN(5,
        'Table2'
        ,CALCULATE(SUM('Table2'[SN]))
        ,DESC
        )    
        ,"topNProduec",'Table2'[Product]
    )
var bottom5Product = 
    SELECTCOLUMNS(
        TOPN(5,
        'Table2'
        ,CALCULATE(SUM('Table2'[SN]))
        ,ASC
        )    
        ,"topNProduec",'Table2'[Product]
    )    
return
--countrows(top5Product)

IF('Table2'[Product] in top5Product,"Top5"
    ,IF('Table2'[Product] in bottom5Product, "Bottom5","something else")
)
   

The result will look this:
image.png

Please be aware that I changed the value for Product K on purpose to avoid getting trapped by the ordering of product/values 🙂
Then just apply/adapt the solution from my first post.

Regards,

Tom

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.