Tag binding, adding transform, if value = 0

Hello all,

If a tag returns a zero, I would like the label to display nothing instead of a zero. I used a transform to format the decimal numbers such as '##.#0'.

I was attempting to add an Expression transform to that but I am not savvy enough with the syntax.

If tag value = 0, then label value = nothing.


Hello mdemaris,

The manual section for Expression Language and Syntax should get you going.


But if you are still having issues, here is an example:

if ({Path/To/YourTag} = 0, "", {Path/To/YourTag}) 
if (evaluation, returns true, returns false)
1 Like

Alternatively, you could also manage this in the transform of a pure Tag Binding:

return value if value != 0 else ""
1 Like

where 'value' is the path to tag?

@user77 I read through that but they don't give an example of the IF statement. Though I almost had it yesterday, going off my VBA knowledge, but I did not include the '( )' so I got an error. So that worked!

If I get the shorter stmt to work, I'll probably use that...less typing, less wordy.

No, in a Transform, the value variable is passed into the script. In the following example, I've modified the format a little bit because I'm not sure exactly how you configured your formatting. I also modified the script transform because after the formatting transform your value will actually be a string.

And then this is what non-zero values look like:

Screenshot 2023-01-05 at 9.11.01 AM


Ok, so we are talking about two different transforms. Using the Expression transform, @user77 provided the stmt for that, and using the Script transform, this is how that would work.

Here is what I'm getting.

same error if I remove the int() function.

null returned if I remove the int and float() functions.

UNLESS! I set the format as you had it, '##.00', instead of '##.#0'

Thank you @user77 and @cmallonee! Both of your suggestions work well!

#0.00 is a safer format to force a 0 before the decimal point. It emphasises decimal rather than, say, ##.00 which would render 0.23 as .23 which could be misread as 23.
Seeing 0.23 is much less ambiguous.


I have one more question on formatting and transforms:

Is it possible to do a group transform without affecting the tags currently bound to the components?

I don't understand the question.

If I select 10 labels, all bound to separate tags, and would like to apply the same transforms to all 10, is this possible without the tag binding changing?

Yesterday I attempted this but all the tags were changed to the same one.

Oh, no; you're overwriting all the bindings with whatever configuration is displayed when you hit "Ok" or "Apply". There is no "Binding Configuration Merge" tool.

If you're gonna use a script transform anyway, you could do your formatting there as well:

return "{:.2f}".format(value) if value != 0 else ""

how would this render 101.9 versus 1.9 values?

Like this:

Screenshot 2023-01-05 at 11.37.03 AM

Just keep in mind that script transforms should be your last resort as they incur slightly higher performance penalties and load on the gateway which is important to manage particularly in large systems, but also good practice

1 Like

.2f means "display as a float with 2 digits after the dot".

1 Like