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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
calen
Helper I
Helper I

Conditional Formatting Not Working

Hello All, 

 

I have each customer ranked by sales for the last 12 months. I also have their rank last year based on sales for the 12 months before that. I want to add conditonal formatting, if their rank went up - show green, if their rank went down - show red. I created the measure below: 

 

Rank Color = IF([Rank]>[Rank LY], 1, IF([Rank]<[Rank LY], -1, 0))
 
Then I formatting the Rank and Rank LY columns to show red a green. 
Here are the results I get based off of that formula and formatting. 
Capture top 20.PNG
 
As you can see, my IF statement is not working. Does anyone know how I can fix my IF statement or get the conditonal formatting to work with another approach? 
1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @calen ,

 

Try the following code:

Condittion = 
SWITCH (TRUE(),
[Rank]>[Rank LY], 1, 
[Rank]<[Rank LY], -1
, 0)

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





View solution in original post

3 REPLIES 3
sanimesa
Post Prodigy
Post Prodigy

@calenYou probably created a column called Rank Color and not a measure, right? I tried your exact scenario and strangely your exact formula works. Not sure why it is producing the incorrect values for you. Would it be possible for you to upload the PBIX?

 

PBI help rank color.PNG

v-alq-msft
Community Support
Community Support

Hi, @calen 

 

Based on your description, I created data to reproduce your scenario.

e1.png

 

You may create a measure as below.

Rank Color = 
var _rank = SELECTEDVALUE('Table'[Rank])
var _rankly = SELECTEDVALUE('Table'[Rank LY])
return
IF(
    _rank>_rankly,
    1,
    IF(
        _rank<_rankly,
        -1,
        0
    )
)

 

Then you need to conditonal format 'Rank' and 'Rank LY' as below.

e2.png

e3.png

 

Result:

e4.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

MFelix
Super User
Super User

Hi @calen ,

 

Try the following code:

Condittion = 
SWITCH (TRUE(),
[Rank]>[Rank LY], 1, 
[Rank]<[Rank LY], -1
, 0)

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.