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

**URL:** <https://forum.inductiveautomation.com/t/max-return-the-tagname-instead-of-value-is-this-possible/34178>\
**Category:** Ignition\
**Created:** [April 23, 2020, 9:49pm UTC](https://forum.inductiveautomation.com/t/max-return-the-tagname-instead-of-value-is-this-possible/34178 "2020-04-23T21:49:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaspinall](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jaspinall](https://forum.inductiveautomation.com/u/jaspinall)\
**Post date:** [April 23, 2020, 9:49pm UTC](https://forum.inductiveautomation.com/t/max-return-the-tagname-instead-of-value-is-this-possible/34178/1 "2020-04-23T21:49:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jaspinall](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jaspinall](https://forum.inductiveautomation.com/u/jaspinall)\
**Post date:** [April 24, 2020, 3:35pm UTC](https://forum.inductiveautomation.com/t/max-return-the-tagname-instead-of-value-is-this-possible/34178/2 "2020-04-24T15:35:00Z")

</div>

Bump

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [April 24, 2020, 4:05pm UTC](https://forum.inductiveautomation.com/t/max-return-the-tagname-instead-of-value-is-this-possible/34178/3 "2020-04-24T16:05:59Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![jaspinall](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jaspinall](https://forum.inductiveautomation.com/u/jaspinall)\
**Post date:** [April 24, 2020, 4:10pm UTC](https://forum.inductiveautomation.com/t/max-return-the-tagname-instead-of-value-is-this-possible/34178/4 "2020-04-24T16:10:33Z")

</div>

Thank you for sharing this.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [April 24, 2020, 11:10pm UTC](https://forum.inductiveautomation.com/t/max-return-the-tagname-instead-of-value-is-this-possible/34178/5 "2020-04-24T23:10:34Z")

</div>

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
