Max() Return the Tagname instead of Value? Is this possible?

Hi All,

Just curious which function you would recommend to accomplish the following:

I have four Integer type tags and I would like write an expression script that returns the ‘tag name’ of the tag which holds the largest value.

Currently i am accomplishing this with the max() function which returns the largest value of all four - this works great right now.

However, I would like to modify this, so that instead of returning the max value, it returns the tagname OF the tag that has the max value.

Any ideas on how I could do this?

Many Thanks.

Bump

This is a bit ‘manual’ but you could try something like this:

case(max({Tag 1}, {Tag 2}, {Tag 3}, {Tag 4}),
	{Tag 1}, "Tag 1",
	{Tag 2}, "Tag 2",
	{Tag 3}, "Tag 3",
	{Tag 4}, "Tag 4",
	""
)

This lets you return whatever text you want when a value matches the maximum.

3 Likes

Thank you for sharing this.

Note: if two tag values are the same and are the Max value together, this will return the first mentioned of the max tags in the expression

1 Like