# Tag Max Value no SQL

**URL:** <https://forum.inductiveautomation.com/t/tag-max-value-no-sql/35649>\
**Category:** Ignition\
**Created:** [June 15, 2020, 12:09pm UTC](https://forum.inductiveautomation.com/t/tag-max-value-no-sql/35649 "2020-06-15T12:09:18Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![damean.thomas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/damean.thomas/32/11367_2.png) [@damean.thomas](https://forum.inductiveautomation.com/u/damean.thomas)\
**Post date:** [June 15, 2020, 12:09pm UTC](https://forum.inductiveautomation.com/t/tag-max-value-no-sql/35649/1 "2020-06-15T12:09:18Z")

</div>

Is there an expression to display the may value of a tag during a given condition without using a SQL query. i just want to show the max value while a condition is true.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 15, 2020, 12:25pm UTC](https://forum.inductiveautomation.com/t/tag-max-value-no-sql/35649/2 "2020-06-15T12:25:01Z")

</div>

You can do this with my objectScript() expression function, thanks to its built-in state dictionary. Something like this:

```auto
objectScript("args[0] if not args[1] or state['mx'] is None or args[0] > state['mx'] else state.mx\nstate['mx'] = __retv",
  {path/to/value/to/track}, {path/to/condition/boolean})

```

Note the buried new-line code that ends the expression and provides an opportunity to execute the assignment into the `state` dictionary.

The above passes the value through when the condition is false, then captures max while true.

---

<div class="post-metadata">

**Author:** ![damean.thomas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/damean.thomas/32/11367_2.png) [@damean.thomas](https://forum.inductiveautomation.com/u/damean.thomas)\
**Post date:** [June 16, 2020, 3:25am UTC](https://forum.inductiveautomation.com/t/tag-max-value-no-sql/35649/3 "2020-06-16T03:25:12Z")

</div>

This is a nice function but is it normal for the tag quality of the tag to turn bad during evaluation?  
Unable to execute object script. I will read through your docs

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 16, 2020, 12:24pm UTC](https://forum.inductiveautomation.com/t/tag-max-value-no-sql/35649/4 "2020-06-16T12:24:41Z")

</div>

Uhm, did you [install my (free) module](https://inductiveautomation.com/moduleshowcase/module/automation-professionals-llc-simulation-aids)?

---

<div class="post-metadata">

**Author:** ![damean.thomas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/damean.thomas/32/11367_2.png) [@damean.thomas](https://forum.inductiveautomation.com/u/damean.thomas)\
**Post date:** [June 16, 2020, 12:56pm UTC](https://forum.inductiveautomation.com/t/tag-max-value-no-sql/35649/5 "2020-06-16T12:56:08Z")

</div>

Yes, I did. The pass through works, but when i enable the condition boolean it errors out.

---

<div class="post-metadata">

**Author:** ![damean.thomas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/damean.thomas/32/11367_2.png) [@damean.thomas](https://forum.inductiveautomation.com/u/damean.thomas)\
**Post date:** [June 17, 2020, 2:19am UTC](https://forum.inductiveautomation.com/t/tag-max-value-no-sql/35649/6 "2020-06-17T02:19:25Z")

</div>

I can see now that as long as the value to track is above mx the expression evaluates but as soon as it drops below the max value the expression no longer evaluates, The max value is there it just has an overlay.  
Thank you for a new path to work on, i’ll keep on it.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 17, 2020, 12:29pm UTC](https://forum.inductiveautomation.com/t/tag-max-value-no-sql/35649/7 "2020-06-17T12:29:10Z")

</div>

I used property notation instead of key access right after the ‘else’. Replace `state.mx` with `state['mx']`. Sorry about that.

---

<div class="post-metadata">

**Author:** ![damean.thomas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/damean.thomas/32/11367_2.png) [@damean.thomas](https://forum.inductiveautomation.com/u/damean.thomas)\
**Post date:** [June 17, 2020, 1:34pm UTC](https://forum.inductiveautomation.com/t/tag-max-value-no-sql/35649/8 "2020-06-17T13:34:03Z")

</div>

> [@pturmel](#):
>
> objectScript("args[0] if not args[1] or state['mx'] is None or args[0] \> state['mx'] else state.mx\nstate['mx'] = \_\_retv", {path/to/value/to/track}, {path/to/condition/boolean})

You have nothing to apologize for, I have been learning alot from your input on the forums. This gives me something else to learn from.

Thank You

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [March 12, 2024, 7:52pm UTC](https://forum.inductiveautomation.com/t/tag-max-value-no-sql/35649/9 "2024-03-12T19:52:28Z")

</div>

To future readers, note that in the version as of the date of my post, using key access with brackets i.e. `state['max']` results in an `Error_ExpressionEval`, likely because the non-existent key at the initialization of the expression will throw a `KeyError`. Fortunately, using `state.get('max')` nicely sidesteps this by just returning `None` instead as desired.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 12, 2024, 8:22pm UTC](https://forum.inductiveautomation.com/t/tag-max-value-no-sql/35649/10 "2024-03-12T20:22:26Z")

</div>

I normally use the dictionary's `.setdefault()` method to ensure an initial value is present.
