Change color of text if value is > x

Im trying to change the color of text when a value is > than x, like this:

WHEN LGV.Duration > ‘00:00:29’ THEN ‘<color=“red”>’

I get an error about the syntax of the WHEN. What am I doing wrong?

Thank you

Hi welcome to the forum, are you using the Vision or Perspective module?
If you’re using an expression binding in Vision, your sintax should probably look something like this:

IF(LGV.Duration > "Place your value here",COLOR(255,0,0),COLOR(0,0,0)

I’ve assumed two things with the code above, other than it being an expression binding in vision:

1- LGV.Duration is the correct path to your value but it doesn’t seem like it, an example of a path would be “{Root Container.Container.Numeric Text Field.intValue}”. If it’s not, you can just find the path to your value by using the “Insert property value” button.
2- The original color of your text is black, if it’s not, change the values accordingly on the second COLOR function.

If it’s Vision and the expression above works, i would recommend you also take at look at these documentation pages for a better understanding on how it works:

https://docs.inductiveautomation.com/display/DOC80/Expression+Overview+and+Syntax
https://docs.inductiveautomation.com/display/DOC81/if
https://docs.inductiveautomation.com/display/DOC81/color

I am using 7.9, its from a query in the reporter, here is the full sql code so far:
SELECT
LGV.EndTime
,LGV.StartTime
,LGV.Distance
,LGV.Duration
FROM
(
SELECT
LGV_Conv_Alarm_3A.End_Time AS EndTime
,LGV_Conv_Alarm_3A.Start_Time AS StartTime
,(LGV_Conv_Alarm_3A.LGV_Dist - 18.63) AS Distance
,FORMAT((LGV_Conv_Alarm_3A.End_Time - LGV_Conv_Alarm_3A.Start_Time),‘HH:mm:ss’) AS Duration
FROM
LGV_Conv_Alarm_3A
WHERE
LGV_Conv_Alarm_3A.LGV_PE_Outfeed_Alarm < 30
) AS LGV
WHERE LGV.Duration > ‘00:00:30’
WHEN LGV.Duration > ‘00:00:29’ THEN ‘<color=“red”>’

Would this change the coloring code?

Oh ok, this changes things a bit.
Unfortunately i don’t know much about the reporting module so other users might be able to provide you with a solution but if you’ll be using it on a table i can point you to the Inductive University video where i believe it shows how to do it the way you want:
https://inductiveuniversity.com/videos/table-row-versioning/8.1
You can also find the same info here:
https://docs.inductiveautomation.com/display/DOC81/Table+Row+Versioning

If you plan to use the text component, then the only way i can think of doing it seems too complicated for it to be the right way, but i might be able to take a better look later on.

Also, i highly recommend you try out all the Inductive University classes, they’re a great way to get you started.

Thank you sir, I will continue my search.

I had a project to replicate some reporting in ignition and needed to change the row color if an event occurred after a certain interval. To do it i created a query data source to retrieve the events, then created a script data source to go through the query data source and determine if the event was after the interval. It then wrote back to the query data source a column “color”. It would put “red” for the past due events, and “white” for everything else. I then bound the row color to the “color” column from the query data source.

Welcome!

Check out:

https://docs.inductiveautomation.com/display/DOC79/Keychain+Expressions

#If the value of "myValue" will determine one of multiple colors:
#Greater than 10 will return Red
#greater than 5 (but not greater than 10) will return Blue
#anything else will return Green.
@myValue>10?"red":myValue>5?"blue":"green"@
1 Like

Note, these are quite slow if you have these expressions evaluating for lots of cells. I was producing a report of some key tank data with ~1000-1500 tanks and tried using these on 4 fields for each tank, and it took ~5mins or so to run the report. Fine for background executed reports, but not so much for ad-hoc user generation.