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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
afloyd2123
Frequent Visitor

Dynamic Conditional Formatting: Green text for YOY growth, Red text for YOY decline

Hi team,

I'd like to use dynamic conditional formatting to show green text for YOY (year over year) growth and red text for a YOY decrease. 

For example: 2022 Total Department is less than it was in 2021. Therefore, I'd like to show the text (109) in red.

 

afloyd2123_0-1652730097178.png

 

Thank you!

1 ACCEPTED SOLUTION
speedramps
Super User
Super User

sorry, I gave you a bad DAX measure

 

Try this ...

 Click here to download a solution 

 

 

RAG colour =

VAR myyear = SELECTEDVALUE(yourtable[Year])

VAR prevyear = myyear -1
VAR myval = SUM(yourtable[Value])

VAR prevval =
CALCULATE(
SUM(yourtable[Value]),
ALL(yourtable),
yourtable[Year] = prevyear )
RETURN
IF( myval >= prevval, "Green", "Red")
 
 
 

View solution in original post

8 REPLIES 8
afloyd2123
Frequent Visitor

Perhaps it was user error but I struggled to get that equation to work. I eventually created a Prior_Year measure, then an IF(Current_Year > Prior_Year, "Green", "Red"). Then using that measure as a field value for the font color within conditional formatting, 

speedramps
Super User
Super User

sorry, I gave you a bad DAX measure

 

Try this ...

 Click here to download a solution 

 

 

RAG colour =

VAR myyear = SELECTEDVALUE(yourtable[Year])

VAR prevyear = myyear -1
VAR myval = SUM(yourtable[Value])

VAR prevval =
CALCULATE(
SUM(yourtable[Value]),
ALL(yourtable),
yourtable[Year] = prevyear )
RETURN
IF( myval >= prevval, "Green", "Red")
 
 
 
speedramps
Super User
Super User

 

Try my original solution again

but take care to follow the instructions on the conditional formating screen

If you can get it working I will creart an example .... but please try DIY thank you !

 

speedramps_0-1652794120723.png

 

speedramps
Super User
Super User

Try this ...

 

add a measure ....

 

RAG colour  =

VAR myyear = SELECTEDVALUE(yourtable[year])

VAR prevyear = myyear -1
VAR  myval = SUM(yourtable[value])

VAR prevval = CALCULATE( SUM(yourtable[value]), yourtable[year]) = prevyear)
RETURN
IF( myval  >= prevval, "Green", "Red)

in conditaional formating select font, format style, = Field Value, RAG colour 

 

Please click thumbs up and accept as solution buttons for such a quick reply. Thanks 😀

It seems that I can't select a measure when I'm using Field Value. Only non-summarized columns.

afloyd2123_1-1652733761525.png

 

In that case, you can have [RAG color] output 1 or 2 (instead of "Green" or "Red") and then use those to format by Rules (instead of Field value)

When I submit what is pictured I receive the error below.

afloyd2123_0-1652792473391.png
MdxScript(Model) (337, 5) Calculation error in measure 'Premium'[RAG colour]: DAX comparison operations do not support comparing values of type Integer with values of type True/False. Consider using the VALUE or FORMAT function to convert one of the values.

 

The error seems to indicate that [RAG color] is outputting True or False instead of 1 or 2.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.